Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help ststic function view pointer

Status
Not open for further replies.

MarcoMB

Programmer
Oct 24, 2006
61
IT
Help please , i need to implement a static function in CView derived class that must return to CDoc derived class the active view pointer...how can i do?
i tried something similar

CSdicap10View* CSdicap10View::GetView()
{


CSdicap10View* pView = GetActiveView();

return pView;
}
it return error GetActiveView undeclared identifier

or also
CSdicap10View* CSdicap10View::GetView()
{

return this;

}

but it return static member functions don't have this pointer and also


CSdicap10View* CSdicap10View::GetView()
{


CFrameWnd * pFrame = (CFrameWnd *)(AfxGetApp()->m_pMainWnd);

CView * pView = pFrame->GetActiveView();

if ( !pView )
return NULL;

if ( ! pView->IsKindOf( RUNTIME_CLASS(CSdicap10View) ) )
return NULL;

return (CSdicap10View*) pView;

}

it doesn't work gve error unhandled exception

how can i do?
Thanks a lot
 
First of all, what exactly are you trying to do with this function?
Second, why do you think it needs to be a static function?
What does you class definition look like?
 
actually i have some CRectTracker object in CView class and i need to serialize them...how could i do?i thonk obtaining a CView oointer from within the CDoc and so get access to CView member to serialize...i'm going wrong?
 
i explain better ... i have a Vector declared in CView derived class

typedef vector <CRectTracker*> TrackerVec;
CRectTracker* pTracker;
TrackerVec myVec;

and a function that creates dinamically CRectTracker objects

std::auto_ptr<CRectTracker> pTracker(
new CRectTracker(rect,CRectTracker::solidLine));

myVec.push_back(pTracker.get());
pTracker.release();


so my question is...how can i serialize this vector and the pointers to CRectTracker objects(and also the objects itself)contained?
 
The simpliest way to go would be to define a static pointer variable of your derived CView class, and set it when the View is created (at constructor for example). Then return this variable from your static function. This is assuming that you only get view created once in the application.

------------------
When you do it, do it right.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top