boost:scoped_ptr
is not copyable so cannot be returned from CreatePage()
. If C++11 is available std::unique_ptr
could be used:
static std::unique_ptr<pagePtr> CreatePage( FunPtrType Ptr2Fun)
{
return std::unique_ptr<pagePtr>(new pagePtr(ptr2Fun));
}
Is there a reason pagePtr
is not copyable? If not and it is inexpensive to copy then return by value.
If pagePtr
is non-copyable and std::unique_ptr
is not available then you could use boost::shared_ptr
to remove the responsiblity from the caller for destructing the returned pagePtr
. With the downside that using shared_ptr
does not indicate sole ownership and pay the price for unrequired reference counting (see What C++ Smart Pointer Implementations are available? for more information and descriptions on the available smart pointers).
From the posted code, pagePtr
appears to a wrapper around a function pointer so consider using boost::function
instead, which is copyable, and remove pagePtr
completely:
typedef boost::function<int(char* sz,
unsigned int max_bytes,
char* arg1,
char* arg2,
char* arg3,
char* arg4)> FunPtrType;