T
toton
Hi,
One more question with smart_ptr ( I am using the one from Axter).
I want to assign the object to the pointer later, not at the
construction time.
like,
smart_ptr<Base> pBase;
///what will be the step here to release the NULL pointer and reduce
the reference count?
pBase = smart_ptr<Base>(new Derived()) ; ///???
Here upon deletion it deletes the Derived twice. Thus I want pBase to
point nowhere and when only it is assigned, the count to increase.
I want it, in case, when the exact derived class is calculated after
some computation, inside constructor (Not in initializer list) and
assigned later.
To give an idea, say the code is a builder like,
class DerivedBuilder{
private:
smart_ptr<Base> pBase;
public:
DerivedBuilder(int type){
if(type < =0) {
pBase = smart_ptr<Base>(new Derived1()) ;
}
else if(type > 0 & <=10){
pBase = smart_ptr<Base>(new Derived3()) ;
}
else{
pBase = smart_ptr<Base>(new Derived2()) ;
}
}
};
Here it is synonymous to boost shared_ptr. I want pBase will call the
destructor only once.
Thanks
abir
One more question with smart_ptr ( I am using the one from Axter).
I want to assign the object to the pointer later, not at the
construction time.
like,
smart_ptr<Base> pBase;
///what will be the step here to release the NULL pointer and reduce
the reference count?
pBase = smart_ptr<Base>(new Derived()) ; ///???
Here upon deletion it deletes the Derived twice. Thus I want pBase to
point nowhere and when only it is assigned, the count to increase.
I want it, in case, when the exact derived class is calculated after
some computation, inside constructor (Not in initializer list) and
assigned later.
To give an idea, say the code is a builder like,
class DerivedBuilder{
private:
smart_ptr<Base> pBase;
public:
DerivedBuilder(int type){
if(type < =0) {
pBase = smart_ptr<Base>(new Derived1()) ;
}
else if(type > 0 & <=10){
pBase = smart_ptr<Base>(new Derived3()) ;
}
else{
pBase = smart_ptr<Base>(new Derived2()) ;
}
}
};
Here it is synonymous to boost shared_ptr. I want pBase will call the
destructor only once.
Thanks
abir