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

Initializer element is not constant trying to define defaults for variables- C

Trying to define the defaults for some variables. For example: static int persist_previousTemp = 1; static int persist_previousTempDefault = 2; static int persist_previousIcon = 1; static int persist_previousIconDefault = 2; //Define variables for…
Edwin
  • 25
  • 7
-1
votes
3 answers

Objective-C: How to prevent a non-default initializer from being called?

I have created a different init method and would like that to be the designated initializer instead of the standard -init. How can I prevent client code from instantiating the class using -init? e.g. /* everyone must call this */ -…
Boon
  • 40,656
  • 60
  • 209
  • 315
-1
votes
2 answers

What is a subroutine and a convenience initializer?

I started learning programming about 8 months ago, started with C, OOP, now onto iOS, which is my goal. Everything is going pretty smooth for the most part and I've started to practice by programming small applications on xcode. It's just little…
-2
votes
1 answer

Instance Initializer Exception Handling

I didn't understand the difference between these codes. One of them is compiled, the other one isn't. { if (true) { try { throw new IOException(); } catch (IOException e) { throw new RuntimeException(e); …
-2
votes
1 answer

C macro for array initialization

I need a macro in C that does this: ARRINIT(10, 0) => {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} As per my understanding however, there is no conventional loop in C macros. So I tried to write a function that takes a number and a void pointer and returns an…
kahveciderin
  • 312
  • 1
  • 3
  • 22
-2
votes
4 answers

Can a condition in a loop be used without an initializer?

As a condition in for or while loops, can you use a statement without "i"? For example: for (let i = 0 ; myArray.length =< 7; i++) I want the loop to run until my condition is met, but not sure if I can achieve that without including the "i" there.
daskas
  • 9
  • 1
-2
votes
2 answers

Create a Car class in python

I have to create a Car class that has the following characteristics: It has a gas_level attribute. It has a constructor (init method) that takes a float representing the initial gas level and sets the gas level of the car to this value. It has an…
EnzoRad
  • 1
  • 1
  • 1
-2
votes
1 answer

A field initializer cannot reference the non-static field, method, or property

I have the following code into a Form: using System; using System.Diagnostics; using System.Drawing; using System.IO; using System.Media; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; namespace…
willy wonka
  • 1,440
  • 1
  • 18
  • 31
-2
votes
2 answers

List(of myclass) initializer vb.net

I have a class like this Class Myclass itemdata as string name as string End Class how do i initialised this class with and array of string for both properties? this is what i am trying, which os obviously wrong Dim ls As New List(Of…
Smith
  • 5,765
  • 17
  • 102
  • 161
-2
votes
1 answer

Initializers in class swift

What is the difference in initializing a variable: class Person { var name = String() } instead of: class Person { var name : String init(name: String) { self.name = name } } thanks
extrablade
  • 363
  • 1
  • 3
  • 16
-2
votes
4 answers

Static variable in an anonymous block in java

Why can't we initialize a static variable in an anonymous block in java? For eg : Why doesn't this code compile? public class A { { static int a = 1; } } I get this compile error saying Illegal modifier for the variable a; only…
Nicholas K
  • 15,148
  • 7
  • 31
  • 57
-2
votes
3 answers

Is there any way to convert a string to a char[] to make something like this work?

I'm trying to get the number of characters in the string without using any library functions. I'm getting an "array initializer must be an initializer list or literal string" error. using namespace std; string stringLength(string myString) { char…
-3
votes
2 answers

Setting a #define value from a method

I'm trying to assign a value to my #define using a method that gets said value from a file. I'm able to get the value from the file and return it to the main method. The define is able to call it and initialize it, but when another method uses said…
Fabzheimer
  • 45
  • 5
-3
votes
1 answer

"initializer list "vs. "default argument value" difference when setting a member value

I've been experiencing a linking issue on a project, and I've found a workaround I can't really explain. I had this kind of class and I was getting an unresolved external symbol on getType<>(), which was correctly imported from another lib. MyClass(…
VincentDM
  • 469
  • 6
  • 17
-3
votes
1 answer

setting initializer (init) in a subclass swift

I'm trying to understand how to call from another class for example let creation = menuButtonController(image:#imageLiteral(resourceName: "maps")) then in menuButtonControlleri set this: class menuButtonController: UIView { let buttonView =…
Fiorelo Odobashi
  • 121
  • 1
  • 1
  • 11
1 2 3
45
46