Boost logo

Boost Users :

From: Alan M. Carroll (amc_at_[hidden])
Date: 2005-10-01 11:22:46


Then your possible solutions are:

1) Require aa,bb to be passed in to the CTest constructor.
2) Add a default constructor for CTest2 and a method to set the aa,bb at some later point.
3) Use scoped_ptr<T>::reset to put a CTest2 instance in the member when you get a valid aa,bb (as described by other responders).

Personally, I'd go with (1) or (2) because otherwise you have to always check whether m_spTest2 is set or not. I like to have my scoped_ptrs always pointing at something, or it's a error condition that needs to be handled. In particular, (2) means that the knowledge of what to do if the CTest2 isn't valid is deferred to CTest2, rather than being in CTest (i.e. less coupling). That's style, though, not an actual requirement of the class.

At 08:19 AM 10/1/2005, you wrote:
>Alan M. Carroll wrote:
>> 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.
>>
>[Yes, that's exactly where my problem comes from, because I cannot get
>the aa, bb from the CTest constructor, and it was passed in later on by
>the user of the class.]


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net