0

I am trying to create a small wrapper-class that lets me use a pointer to a pointer like it was just a normal pointer(just for convenience). I came up with the following code:

template<typename T>
    class PtrPtr
    {
    public:
        PtrPtr() = default;
        PtrPtr(const T** ptr) : m_ptr(ptr) {  }
        inline void operator =(const T** ptr) { m_ptr = ptr; }
        inline void operator =(T** ptr) { m_ptr = ptr; }

        inline operator T*() const { return (*m_ptr); }

        inline T** get() const { return m_ptr; }
    private:
        T** m_ptr;
    };

I thought the operator inline operator T*() const { return (*m_ptr); } would make it possible to use the class as if it were a pointer to T, however it doesn't seem to work when I try to access T's elements with the following syntax:

PtrPtr<myStruct> ptr = function that returns a pointer to pointer to myStruct;
ptr->some member of myStruct; <-Gives an error
static_cast<myStruct*>(ptr)->some member of myStruct; <-works but obviously tedious syntax

Note that when I specifically cast "PtrPtr ptr" to a T* and then try to access its members with the "->"-operator it seems to work. Any Ideas if it is possible to acheive a clean syntax here?

1 Answers1

0

The solution is to over load the ->-operator. This thread explains how it is done.