S
subramanian100in
Consider the following program:
#include <iostream>
using namespace std;
class Test
{
static Test t;
static Test init_Test( ) { return t; }
Test(const Test & rhs) { cout << "copy ctor" << endl; }
};
Test Test::t = init_Test( );
int main()
{
return 0;
}
This program compiles fine under both g++ and VC++2005 Express Edition
and both produce the following same output
copy ctor
However consider the statement
Test Test::t = init_Test( );
Here init_Test( ) is called which returns the static member object
under construction which is 't'. I do not understand how we can
return an object which is still under construction.
How is it accepted by the compiler ?
Kindly explain
Thanks
V.Subramanian
#include <iostream>
using namespace std;
class Test
{
static Test t;
static Test init_Test( ) { return t; }
Test(const Test & rhs) { cout << "copy ctor" << endl; }
};
Test Test::t = init_Test( );
int main()
{
return 0;
}
This program compiles fine under both g++ and VC++2005 Express Edition
and both produce the following same output
copy ctor
However consider the statement
Test Test::t = init_Test( );
Here init_Test( ) is called which returns the static member object
under construction which is 't'. I do not understand how we can
return an object which is still under construction.
How is it accepted by the compiler ?
Kindly explain
Thanks
V.Subramanian