到底是什么(*),您如何投射?

"error C2440: '=' : cannot convert from 'char *[]' to 'char (*)[]'"

试图让SmartPointer获取数组值。 header :
template <typename T> class SmartPointer
{
private:
    T* myPtr;
    int* count;

public:
    T* Value();

    SmartPointer(const SmartPointer<T>& a)
    {
        myPtr = a.myPtr;
        count = a.count;
        ++*count;
    }
SmartPointer(T* ptr);
SmartPointer(T value) { myPtr = &value; count = new Int(); ++*count; }
~SmartPointer();


void operator =(T a);
operator T*();
    T* operator ->();
};

相关 call 线路:
SmartPointer<char[]> str = SmartPointer<char[]>(new char[20]);

最佳答案

我对这门课不熟悉,但我认为您想要:

SmartPointer<char> str = SmartPointer<char>(new char[20]);

或可能:
SmartPointer<char> str = new char[20];

07-24 09:46