In the following example, I get:
error C2300: 'UnmanagedClass' : class does not have a finalizer called '!SmartPointer'
If I remove the operator->, this error goes away. Could someone explain why this is happening?
// Unmanaged class.
class UnmanagedClass { };
public ref class SmartPointer {
public:
SmartPointer(UnmanagedClass* u) : m_ptr(u) { }
~SmartPointer() { this->!SmartPointer(); }
!SmartPointer() { delete m_ptr; }
// This line triggers C2300.
UnmanagedClass* operator->() { return m_ptr; }
};
int main() {
SmartPointer^ s = gcnew SmartPointer(new UnmanagedClass);
}