Cyclic Creation Dependency ?
Hi all,
Can anyone explain to me why the copy constructor of the COuterClass is
getting called for this one? Let me start by saying I reckon this is
seriously bad way of implementing anything of the sort, we have a way
around this. I am simply trying to understand the order or creation and
the reason for the call to the COuterClass copy constructor. Any help
would be seriously appreciated. Thanks in advance.
class COuterClass;
//=============================================================================
//
// CInnerClass
//
//=============================================================================
class CInnerClass
{
public:
COuterClass* theOuterClass;
explicit CInnerClass( COuterClass* pOuterClass ) :
theOuterClass( pOuterClass )
{
cout << "CInnerClass( COuterClass* pOuterClass )" << endl;
}
private:
CInnerClass( ){};
CInnerClass( const CInnerClass& rhs){};
const CInnerClass& operator=( const CInnerClass& rhs ) {};
};
//=============================================================================
//
// COuterClass
//
//=============================================================================
class COuterClass
{
public:
CInnerClass theInnerClass;
COuterClass( ) :
theInnerClass( this )
{
cout << "COuterClass( )" << endl;
};
private:
COuterClass( const COuterClass& rhs ){};
const COuterClass& operator=( const COuterClass& rhs ) {};
};
int main( ... )
{
COuterClass theOuterClass;
}
the error I am getting is :
--------------------Configuration: CyclicDependency - Win32
Debug--------------------
Compiling...
CyclicDependency.cpp
C:\Temp\CyclicDependency\CyclicDependency.cpp(54) : warning C4355:
'this' : used in base member initializer list
C:\Temp\CyclicDependency\CyclicDependency.cpp(61) : error C2248:
'CInnerClass::CInnerClass' : cannot access private member declared in
class 'CInnerClass'
C:\Temp\CyclicDependency\CyclicDependency.cpp(38) : see
declaration of 'CInnerClass::CInnerClass'
Error executing cl.exe.
CyclicDependency.exe - 1 error(s), 1 warning(s)