23 questions
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 ...
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 ...
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 = ...
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....
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 ...
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
...
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?!
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 ...
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 &) {}
};
...
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 ...
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 ...
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 ...
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,...
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-&...
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 = "...