Initializers are called to create a new instance of a particular type. In its simplest form, an initializer is like an instance method with no parameters
Questions tagged [initializer]
684 questions
5
votes
3 answers
Correct syntax to initialize static array
I have following code definig an array
public class PalphabetsDic
{
public static string[] PAlphCodes = new string[3] {
PAlphCodes[0] = "1593",
PAlphCodes[1] = "1604",
PAlphCodes[2] = "1740",
};
}
When I use…

Ali Padida
- 1,763
- 1
- 16
- 34
5
votes
1 answer
Are Objective-C initializers allowed to share the same name?
I'm running into an odd issue in Objective-C when I have two classes using initializers of the same name, but differently-typed arguments. For example, let's say I create classes A and B:
A.h:
#import
@interface A : NSObject {
}
-…

NattKatt
- 51
- 2
5
votes
2 answers
Fields Initilizers (Static or not) and Constructor (Static or not) which one runs first
Something is not clear to me, according to what I read:
Field Initializers run before Constructors.
Static field Initializers execute before the static constructor is called (which is still compatible with point 1.).
If a type has no static…

AymenDaoudi
- 7,811
- 9
- 52
- 84
5
votes
0 answers
Initialization of C struct in C++
For a microcontroller project I'm working on, I'm writing a shared library. I'm mixing C and C++, mainly because of all the pointer arithmic that needs to be done in a low level part and because then my code easily maps on the C libraries. On a…

Chris de Jong
- 51
- 2
5
votes
3 answers
Can I create an anonymous, brace-initialized aggregate in C++?
One can create an anonymous object that is initialized through constructor parameters, such as in the return statement, below.
struct S {
S(int i_, int j_) : i(i_), j(j_) { }
int i, j;
};
S f()
{
return S(52, 100);
}
int main()
{
cout <<…

plong
- 1,723
- 3
- 14
- 14
5
votes
2 answers
Rails: Translation in Initializer
I have several translations tucked away into an initializer like so:
GROUP_GOVERNANCE_STYLES = [
[I18n.t("constants.group_governance_styles.collective"), 1],
[I18n.t("constants.group_governance_styles.electoral_democracy"), 2],
…

nullnullnull
- 8,039
- 12
- 55
- 107
5
votes
1 answer
initializer_list in visual studio 2012
I found that initializer_list is not supported by MSVC 2012. But can it (initializer_list)
be used in VS somehow (with the help of Boost library for example). Samples if you can, please.

Nabijon
- 821
- 2
- 13
- 17
5
votes
2 answers
python multiprocessing - Best way to initialize/pass database connection to be used across processes
I am having some difficulty in passing a database connection object or the cursor object using pool.map in the Python multiprocesing package. Basically, I want to create a pool of workers each with its own state and a db connection, so that they can…

Angela
- 1,671
- 3
- 19
- 29
5
votes
3 answers
initialize a union array at declaration
I'm trying to initialize the following union array at declaration:
typedef union { __m128d m; float f[4]; } mat;
mat m[2] = { {{30467.14153,5910.1427,15846.23837,7271.22705},
{30467.14153,5910.1427,15846.23837,7271.22705}}};
But I'getting the…

albertgumi
- 322
- 1
- 4
- 13
5
votes
3 answers
how to get domain url in initializer file, rails
i was wondering if it was possible to get the domain url ie
localhost or myapp.heroku.com
from an initializer file?
i believe the
request.url
and the request methods only work in controllers. is there an equivalent to the…

Sasha
- 3,281
- 7
- 34
- 52
4
votes
2 answers
Rails: Get hostname in an initializer
I'm using Sorcery for Authentication, and I need to setup third party authentication in its initializer.
The initializer has a line that looks like this:
config.twitter.callback_url "http://example.dev/auth/callback?provider=twitter"
...where…

Andrew
- 42,517
- 51
- 181
- 281
4
votes
3 answers
Using image_path helper in a custom yml.erb file in config directory written through a custom initializer
I built a yml.erb file that will be used for configuring some parts of my application.
I would like to preload it with an initializer (I don't require it to change during application running), the biggest problem is that this yml file contains link…

Francesco Belladonna
- 11,361
- 12
- 77
- 147
4
votes
1 answer
Run an rspec "before" block before rails initializers run
I would like to run an rspec before block to set some stuff up before the Rails initializers run, so I can test what an initializer should be doing. Is this possible?

Pistos
- 23,070
- 14
- 64
- 77
4
votes
1 answer
Rails 7 Engine Initializer Hook Not Working
trying to get my gem working in Rails 7. I have confirmed it works in Rails 6.1.4.1 (latest).
In my engine's engine.rb file I have this...
module MyEngine
class Engine < ::Rails::Engine
isolate_namespace MyEngine
initializer…

Chris A.
- 183
- 11
4
votes
1 answer
Property 'filteredOptions' has no initializer and is not definitely assigned in the constructor
in my Angular app i have a component:
filteredOptions: Observable;
Following line give the error:
Property 'filteredOptions' has no initializer and is not definitely assigned in the constructor.
28 filteredOptions:…

tarun sharma
- 43
- 4