Skip to main content
77 votes
2 answers
13k views

What are the differences between C-like, constructor, and uniform initialization?

To the best of my knowledge, there are three ways to initialize a variable in C++. int x = 0; // C-like initialization int x (0); // Constructor initialization int x {0}; // Uniform ...
dayuloli's user avatar
  • 17k
2 votes
1 answer
131 views

What's the difference between Radio r = Radio("PSR", 100.8) and Radio("PSR", 100.8)? [duplicate]

I'm new to C++ and trying to understand something. I have this code in my main.cpp: Radio r = Radio("PSR", 100.8); or that code: Radio r("PSR", 100.8); Both seem to work and ...
Sten Göring's user avatar
100 votes
11 answers
190k views

Declare and assign multiple string variables at the same time

I'm declaring some strings that are empty, so it won't throw errors later on. I've read that this was the proper way: string Camnr = Klantnr = Ordernr = Bonnr = Volgnr = Omschrijving = Startdatum = ...
Mathlight's user avatar
  • 6,633
22 votes
5 answers
15k views

Stop a periodic task from within the task itself running in a ScheduledExecutorService

Is there a nice way to stop the repetition of task from within the task itself when running in a ScheduledExecutorService? Lets say, I have the following task: Future<?> f = scheduledExecutor....
akarnokd's user avatar
  • 70k
21 votes
9 answers
29k views

Declaring vs Initializing a variable?

I'm curious to know the difference between declaring a variable, and initializing a variable. e.g. var example; // this is declaring var example = "hi" // initializing? Or just "adding a value"? I ...
user3247128's user avatar
10 votes
2 answers
11k views

How to initialize to zero/NULL in a template

While writing a template, I want to initialize my variable to a value that serves as zero or null the the data type. If I set it to 0x00 is it going to serve as zero/NULL for any type ? for example ...
user avatar
5 votes
4 answers
7k views

Does an int in Objective-C have a default value of 1?

I have this simple line of code: int x; x automatically has the value of 1. I don't set it to anything but when I debug, it shows that x is 1. Does an int have a default value of 1?!
aryaxt's user avatar
  • 77.6k
4 votes
3 answers
258 views

Variable initialization (pointer and value)

Foo f1 = Foo(); // (1) Ok Foo f2 = Foo; // (2) Compiler error Foo *p1 = new Foo(); // (3) Ok Foo *p2 = new Foo; // (4) Ok. Why?? I was wondering why there exists two ways to initialize ...
Loom's user avatar
  • 9,976
3 votes
1 answer
249 views

Why can't I access a member of this class? [duplicate]

I have the following three class definitions: class String { public: String() {} String(const char *) {} }; class ClassA { public: ClassA(const String &) {} }; ...
Nathan Osman's user avatar
  • 73.1k
2 votes
4 answers
113 views

Can a variable declaration refer to other variables declared on the same line?

I use this syntax often but I don't understand why it simply works. var a = 1, b = a + 1; console.log(b); // 2 In the event you're declaring a var, after splitting them on a comma, the b already ...
voldomazta's user avatar
  • 1,340
0 votes
1 answer
499 views

variable may not have been initialized

inside of the arrayAverage method, avg has the right value (I tested it by puting println (avg) inside of the method. When i call the method from my main method and then print avg, netbeans tells me ...
user2809114's user avatar
22 votes
4 answers
108k views

C: Cannot initialize variable with an rvalue of type void*

I have the following code: int *numberArray = calloc(n, sizeof(int)); And I am unable to understand why I receive the following error. Cannot initialize a variable of type 'int *' with an rvalue of ...
user3662185's user avatar
17 votes
5 answers
3k views

How is this possible to use in c++?

To my surprise, I found that the name of a c++ object can be the same as class name. Can someone explain to me the reason why? When I declare an object of class a as a a1(), it does not raise an error,...
nihar's user avatar
  • 153
16 votes
5 answers
22k views

Which is the better approach to initialize php properties?

Here are two way to initialize class variables. 1st Method class Test { private $var1; private $var2; public function Test($var1,$var1) { $this->var1 = $var1; $this-&...
Starx's user avatar
  • 78.9k
11 votes
7 answers
16k views

Java String initialization

Which do you prefer and why" String myString = null; if(someCondition) myString = "something"; else myString = "something else"; OR String myString = ""; if(someCondition) myString = "...
ewa's user avatar
  • 429

15 30 50 per page