What default constructor?
imagine the following sudo like code
class A
{
A();
A(int, int);
};
main
{
A varname; // no problem
A varname(1, 2); // no problem
A varname(); // problem !!!
}
Why can't you use the so called optional parenthesis in this example?
My first thought was the compiler sees this as invalid chars for the variable name, but this compiles.
So i added a line after the problem statement using the varname and then it won't compile.
This leaves me to beleive that the compiler just ignores the problem statement if you don't acually use it. By the way this is the same for g++ as well as msvc compilers.
So, is there a good reason why this won't just call the default constructor?
Just curious ... :)
Re: What default constructor?
Is a declaration of a function which has no parameters, returns "A" and is called varname ;)
Everything which looks like a function IS A function
Re: What default constructor?
"A varname();" is a declaration of a varname function returning A.
Edit: Great, someone was a bit faster :)
Re: What default constructor?
So why is it that:
A varname(1,2);
is not a declaration of a function, but instead calls a function constructor and assigns the new instance to a variable called varname.
Re: What default constructor?
Quote:
Originally Posted by bitChanger
is not a declaration of a function, but instead calls a function constructor and assigns the new instance to a variable called varname.
Because you can't specify values in declarations this way.
This would be a declaration:
Code:
A function1( int, int );
A function2( int a, int b );
A function3( int a = 1, int b = 2 );
Re: What default constructor?