Thank you for the link. The case which you are refering is quite different from what we are discussing.
I've tried this on VC++ 6.0 and it works absolutely fine.
Could you please justify your statement
"You cannot call a constructor's body in this way. " ??
Please post the Error which you got while compling this code on g++.
Even this is going to work
void main()
{
base::base("hellothere");
}
Here a temporary object will be created.
Also in our case. base::base() will NOT be intepreted as variable declaration.
The case you are talking about is this ( from your refrence link)
Foo x(Bar());
What main should return is secondary.
OMG, if it works with VC++ 6.0, then it must be right. LOL ;)
I did try it and low and behold it did work without warnings (no surprise as it is a MS compiler ;)). But even it doesn't do what you think. Try and putting a line like these:
-
// Place in base::base()
-
cout << "base::base() called. this = " << this << endl;
-
-
// Place in base::base(char *)
-
cout << "base::base(char *) called. this = " << this << endl;
-
Oh, you might also want to put something similar in base's destructor.
It will surprise you by showing you that it is creating a temporary variable. Not calling the constructor on the current instance like it would if you put it where we stated it should be. (BTW, this is not what the standard says it should do which translate roughly into "If it looks like a declaration, it is.")
Under g++ (also not always the best compiler to use for such tests, but IMHO better than VC++) it does get it right in that it thinks that
base::base(temp); is a declaration. Though even I was surprised that it would since the type appears to be the constructor, but apparently, base(temp) is equivalent to base::base(temp).
If you want the best test, Comeau is reportedly the best (comp.lang.c++ refer to it quite a bit) in implementing C++ in accordance to the standard. I've not bothered yet to download their compiler, but I will when I get my flaky drive repaired.
The link stating
Foo x(Bar()) is only the tip of the iceberg.
Foo(x); is equivalent to Foo x; under properly conforming compilers.
Have I justified myself enough?
Adrian