Questions tagged [initializer]

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

684 questions
-1
votes
1 answer

printf in C with strings that has shorter initializer behaves weird

So I tried to make character arrays and play around with it. #include #include #include int main(int argc, char ** argv) { char str1[11] = "Yo! Angelo!~"; //total length of 12, initializer is shorter char…
Mohanna J
  • 15
  • 3
-1
votes
1 answer

Why Array initializer is not Allowed here? What is the problem

class Main { public static void main() { int[] array = new int[5] {1,2,3,4,5}; } }
-1
votes
2 answers

Can anybody explain this initializer code?

Can anybody explain how "self_( this, []( ... ) {} )" works? struct Parent { std::shared_ptr self_; Parent() : self_( this, []( ... ) {} ) {} operator std::shared_ptr() const { return self_; } }
SyCoDeR
  • 23
  • 4
-1
votes
1 answer

Initialize static class member with an instance of a derived class if type is a reference to a pure virtual base class

When I try to initialize a static member in my Action.cpp file via ILogger & Action::m_activeLogger = DefaultLogger(); the compiler (C++11 + Linux) says: cannot bind non-const lvalue reference of type "ILogger &" to an rvalue of type ILogger How…
R Yoda
  • 8,358
  • 2
  • 50
  • 87
-1
votes
1 answer

Swift - How to initialize property in subclass when there is a required initializer to be satisfied?

As per title. Because of the required init(a:), I can't initialize 'b', unless I resort to overloading as above. Question (1): Is there a better way of approaching this? It seems a little off looking at self.b=0 has to be included there. class…
-1
votes
1 answer

Can i put a empty return statement inside an instance initializer?

I'm am trying to put a empty return statement inside an instance initializer block to exit in case the string is null but compiler say "Cannot return from within an initializer" , i have found this answer this answer on stack-overflow but it's about…
Mike D3ViD Tyson
  • 1,701
  • 1
  • 21
  • 31
-1
votes
1 answer

Rails - How to access data generated in an initializer from controller

I have a ruby on rails app where I utilize AWS Products API. This api has a throttle. So I set up a scheduler using the rufus scheduler gem to to query the api every second, n times. I put the scheduler in an initializer because I wanted to get…
-1
votes
2 answers

Setting properties of an instance the same way as object initializer

What i'd like is having an object initializer, but for an instance of object that has already been created. Something like this: MyClass myObj = MyClass.NewObj(); //... myObj { prop1 = val1, prop2 = val2, ... prop50 = val50 }; This would be much…
-1
votes
2 answers

Initializes an array by a given size in random values between 1 and 500 in c

I have assignment to write program that sort an array and search for a specific number, that part I've already done, My problem is how to Initialize the array in the size that the user sets with random values ​​smaller than 500? I know how to do…
Shay Doron
  • 179
  • 2
  • 10
-1
votes
1 answer

How do I initialize a float array, with variable lengths, inside the code, but with the same start and end values?

PdfPTable table = new PdfPTable(new float[]{4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}); This is the initializer I currently use. It's for a scorecard in Disc Golf, using integers to tell how wide each cell should be, but some courses have different…
Luke Goss
  • 31
  • 1
  • 1
  • 3
-1
votes
1 answer

Error message: initialiser for conditional binding must have optional type, not '()'

I am getting error: initialiser for conditional binding must have optional type, not '()'. Using Swift language, below is the code: if let result = brain.performOperation(operation)
jd1122
  • 3
  • 1
-1
votes
5 answers

I do not understand Objective-C Initializer for a class.

This code is from the Sams Teach Yourself Swift book, Chapter 21. The Song.h file contains the following code: //Song.h #import @interface Song : NSObject; @property (nonatomic, copy) NSString *title; @property (nonatomic,…
-1
votes
2 answers

Java Initializer exception using JxBrowser library

I am trying to run some of Jx Browser's samples. After copying and pasting the sample code provided by it, and trying to run it, it gives me an Initializer error. here is the sample code and the exception. Can anybody tell me what's going…
lonesome
  • 2,503
  • 6
  • 35
  • 61
-1
votes
1 answer

Objective-c initializer creates two different objects instead of one

I have got a strange bug I cannot seem to figure out. I've got a class called SPGamePlayScene. I also have a class called SPPracticeScene with inherits from SPGamePlayScene. I want SPPracticeScene to do all the stuff SPGamePlayScene does in its…
Stone Preston
  • 1,828
  • 4
  • 20
  • 35
-1
votes
2 answers

How to reload initializer for each record update

In my application I am using one global variable which is defined in config/initializers/details.rb $available_plans= Plan.all and using this variable, all over the application and this will be available to all users. If I add one more plan, that…