I initialize scoped_ptr in the member initialization list frequently. You should be able to do it as well. However, I can't guess at what your problem is because 1) I don't know what error you are getting 2) I don't know what the constructor for CTest2 looks like What I suspect is that you are passing the wrong argument to the initializer for m_spTest2. It should be something like : m_spTest2(new CTest2(aa, bb)) Where you'd get instances for aa and bb from the default CTest construct is unclear, but that could the actual problem. Alternately, you would need to have CTest2 defined "near" the definition of the CTest() constructor, because the CTest constructor invokes a method of CTest2. If defined outside the class, that would be somewhere before the definition. If defined in CTest, then it could be as late as the closing brace of the class (if CTest2 is a nested class). At 06:04 PM 9/29/2005, you wrote:
New to this topic,and need some help here.
I have a class which use the scoped_ptr as a member variable.
Class CTest { public: CTest(); Initialize(); ~CTest(); private: scoped_ptr<CTest2> m_spTest2; }
For some reason, that I cannot initialize m_spTest2 in the member initialization list of the constructor, so I have to initialize in some other functions like in Initialize.
CTest::Initialize() { int aa, bb; m_spTest2=new CTest2(aa, bb); }
The compiler will complain about that, so what's the right way to do it.
Thanks, Jianwei
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users