The problem is that std::unique_ptr<T>
cannot be cast to T*
; and, in general, you should not be using C-style casts in C++. Your comment about the GetWidth
and GetHeight
lines is fair, but this is because of the operator overloading: indeed, this says nothing about the cast-ability of the type; it merely makes it behave like the underlying type pointer with regard to dereferencing. The raw pointer (the memory underlying the unique_ptr
) can be obtained through myVec[0].get()
, but then I'd ask why you are using smart pointers in the first place.