Hello,
I have currently the following problem: I want to use the SmartPointer with an array type datatype e.g. char[13].
The following contructors are implemented:
1.) SmartPointer () default constructor with empty payload
2.) SmartPointer (uint8_t size) Allocates memory from the given size.
3.) template<typename T > SmartPointer (const T *data)
4.) SmartPointer (const SmartPointer &other)
The third variant is not useable with pointer type data, because the memory gets only calculated for the size of the pointer.
Are you sure about this? sizeof(char[13]) is 13 and different from sizeof(char*). None the less I don't think it would be the right solution.
So the next solution would be to use variant 2, but then there is no way
to fill the data array. There are only getter functions and no setter functions. Thus i would suggest to add another constructor type
template<typename T > SmartPointer(const T *data, int size) which allocates size*sizeof(T) memory. For this solutions also getter functions with a size parameter have to be added. The pointer is not type-safe anyway. If you can think up a better solution, please tell me.
I would prefer a separate array smart pointer. Since the access functions for objects and arrays are different, a new class would be the better choice than to add a second (and orthogonal) interface to the smart pointer class. Cheers, Fabian