making some simple tries about initializations (and default constructors) of object and primitives in C++, I found a behaviour that I don't understand, so I need an help.
Let's first talk about primitives types.
The code I tested is the following:
int main() {
int i(5);
cout<<i<<endl;
int j();
cout<<j<<endl;
int k;
cout<<k<<endl;
return 0;
}
The result I get is this:
5
1
6487956
Obviously I was especting the first result (initialization in object style), and also the third (not initialized value), but the second? About the second, I was especting a default initialization, instead I get a warning that told "the address of 'int j()' will always evaluate as 'true'"... Infact the printed result is 1, but what kind of sintax is the empty round brackets near a primitive variable?
And now about the object, the case is similar... The code is:
class Pluto {
public:
int a;
int b;
Pluto() {
a = 0;
b = 0;
std::cout<<"Constructor call"<<std::endl;
}
}
int main() {
Pluto p();
}
I have a class with a default constructor inside which I've put a print to underline its invocation, then I declare an object with a similar sintax to the previous case, and I was expecting a call to the default constructor, while I get nothing in output, so the constructor was not called. In a next test, I try to access the members of the object, but I get the error "Field 'a' could not be resolved".
I'm sure that the anwer to my question is stupid and obvious, but now I really can't find it, so thanks to who will help me.