Hello, my base class need to expose a method that for some derived classes would return a smart pointer to dynamically allocated array, and for some other derived classes would return a pointer/reference to statically allocated one.
example:
class Base
{
public:
virtual ??? foo()=0;
}
class A : public Base
{
private:
float arr[10];
public:
??? foo(){ return ???arr; }
}
class B : public Base
{
public:
??? foo(){
allocate array;
return ???array;
}
}
The dynamically allocated array is created inside class method and I would prefer to use a std::unique_ptr
. But what should I do for the statically allocated array in class A
?
Should I create own class derived from std::unique_ptr
that would be aware of pointee allocation and would not try to destroy statically allocated pointee, or maybe there already exist such smart pointers?