Re: Scope of constructor initialisation list
....sorry presed the wrong button by mistake..
Here's the entire message again:
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 mainThread;
public:
CMyThread()
//: CThread(m_pThreadFunctor = new
CMyThreadFunctor(this)) <<<< SCOPE-1
{
mainThread=(m_pThreadFunctor = new
CMyThreadFunctorIMO(this)); <<<<SCOPE-2
}
};
Could you please tell me what am i doing wrong here and what is the
sccope of the two lines?
Thanks