V
v4vijayakumar
Is there any way to defer instantiation of " t1" to the constructor of
"test1"? because, "t1" can only meaningfully initialized in the "test1"
constructor.
#cat test.cpp
#include <iostream>
using namespace std;
class test
{
public:
test()
{
cout << "hello" << endl;
}
};
class test1
{
test t;
public:
test1()
{
cout << "hello1" << endl;
}
};
int main(int argc, char *argv[])
{
test1 t1;
return 0;
}
#g++ test.cpp
#./a.out
hello
hello1
#
thanks in advance.
"test1"? because, "t1" can only meaningfully initialized in the "test1"
constructor.
#cat test.cpp
#include <iostream>
using namespace std;
class test
{
public:
test()
{
cout << "hello" << endl;
}
};
class test1
{
test t;
public:
test1()
{
cout << "hello1" << endl;
}
};
int main(int argc, char *argv[])
{
test1 t1;
return 0;
}
#g++ test.cpp
#./a.out
hello
hello1
#
thanks in advance.