I have a class that creates an object inside one public method. The object is private and not accessible to users of this class. Then this method calls other private methods within the same class and passes the created object as a parameter:
class Foo {
...
};
class A {
private:
typedef scoped_ptr<Foo> FooPtr;
void privateMethod1(FooPtr fooObj);
public:
void showSomethingOnTheScreen() {
FooPtr fooObj(new Foo);
privateMethod1(fooObj);
};
};
I believe that the correct smart pointer in this case will be scoped_ptr, however I cannot do this because scoped_ptr makes the class incompatible if it is used this way, so I have to make such methods as follows:
void privateMethod1(FooPtr& fooObj);
privateMethod1 does not save the object; it does not save references to it. Just retrieves data from the Foo class.
, , - , , , , .
, scoped_ptr.