I'm developing a SDI multiview application with MFC and I'm using to access at a view class from a child dialog.
To do this I'm using a casting in this way:
CView* v = ((CFrameWnd*) m_pMainWnd)->GetActiveView();
((MyView*)v)->MyFunction_in_Parent();
When I exit method must I delete *v pointer? Or set to null?
Any not CView pointer deletion will bring problems?
When I exit method must I delete *v pointer? Or set to null?
Neither. v is a local variable that's not longer accessible after leaving scope (function) hence it makes no sense to assign null when it's not longer existent.
Imporant is that only that object that has the ownership of the pointer (called new) is supposed to call delete.
better use dynamic_cast<...*> so that you know that the object has the right type. dynamic_cast returns null if it's the wrong type