Re: Cyclic Creation Dependency ?
<sakis.panou@btinternet.com> wrote in message
news:1147799984.932102.274360@y43g2000cwc.googlegroups.com...
: 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:
:
The error is reported for this line: [ you should have indicated
this in your post ]
: COuterClass( const COuterClass& rhs ){};
The copy constuctor does not specify how to construct/initialize
member theInnerClass. Therefore its default constructor has
to be called -- but it is inaccessible (private to theInnerClass).
Has nothing to do with a cyclic dependency...
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com