M
Matthias Kaeppler
Hi,
I'm having a hard time figuring out how I can initialize a smart pointer
based on a certain condition:
if something then
ptr = 0; // init with NULL
else
ptr = new XYZ; // init with a sane value
endif
I know assignment doesn't work for a smart pointer unless the assigned
value is a smart pointer itself.
Any ideas how I can trick the compiler to do what I need? The problem is
simply that smart pointers expect the pointee to be passed to their
ctor, but the ctor is only called once.
Regards,
Matthias Kaeppler
I'm having a hard time figuring out how I can initialize a smart pointer
based on a certain condition:
if something then
ptr = 0; // init with NULL
else
ptr = new XYZ; // init with a sane value
endif
I know assignment doesn't work for a smart pointer unless the assigned
value is a smart pointer itself.
Any ideas how I can trick the compiler to do what I need? The problem is
simply that smart pointers expect the pointee to be passed to their
ctor, but the ctor is only called once.
Regards,
Matthias Kaeppler