P
Pantokrator
Hi all,
I've got a question about the scope of the constructor initialisation
list. First of all, let me explain my classes:
// *****************************************************
class CThread
{
CThread(){};
CThread(CMyThreadFunctor *pThreadFunctor)
{
...
};
};
// *****************************************************
class CMyThreadFunctor
{
....
};
// *****************************************************
class CMyThread : public CThread
{
CMyThreadFunctor *m_pThreadFunctor;
public:
CMyThread()
: CThread(m_pThreadFunctor = new CMyThreadFunctor(this)) <<<<
SCOPE-1
{
//CThread(m_pThreadFunctor = new CMyThreadFunctorIMO(this));
<<<<SCOPE-2
}
};
When I init the CThread object using the constructor init list
(SCOPE-1), my CThread object runs fine without a problem. If I init
CThread within the constructor (SCOPE-2), my CThread calls the
destructor straight after initialisation and I suspect that it is
related to the scope of the object. I even tried the following but
without any luck:
class CMyThread : public CThread
{
CMyThreadFunctor *m_pThreadFunctor;
CThread
public:
CMyThread()
: CThread(m_pThreadFunctor = new CMyThreadFunctor(this)) <<<<
SCOPE-1
{
//CThread(m_pThreadFunctor = new CMyThreadFunctorIMO(this));
<<<<SCOPE-2
}
};
I've got a question about the scope of the constructor initialisation
list. First of all, let me explain my classes:
// *****************************************************
class CThread
{
CThread(){};
CThread(CMyThreadFunctor *pThreadFunctor)
{
...
};
};
// *****************************************************
class CMyThreadFunctor
{
....
};
// *****************************************************
class CMyThread : public CThread
{
CMyThreadFunctor *m_pThreadFunctor;
public:
CMyThread()
: CThread(m_pThreadFunctor = new CMyThreadFunctor(this)) <<<<
SCOPE-1
{
//CThread(m_pThreadFunctor = new CMyThreadFunctorIMO(this));
<<<<SCOPE-2
}
};
When I init the CThread object using the constructor init list
(SCOPE-1), my CThread object runs fine without a problem. If I init
CThread within the constructor (SCOPE-2), my CThread calls the
destructor straight after initialisation and I suspect that it is
related to the scope of the object. I even tried the following but
without any luck:
class CMyThread : public CThread
{
CMyThreadFunctor *m_pThreadFunctor;
CThread
public:
CMyThread()
: CThread(m_pThreadFunctor = new CMyThreadFunctor(this)) <<<<
SCOPE-1
{
//CThread(m_pThreadFunctor = new CMyThreadFunctorIMO(this));
<<<<SCOPE-2
}
};