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!

Inter-Class access?

Status
Not open for further replies.

panioti

Programmer
Jan 5, 2005
15
US
I'm learning to cope with the mfc; and trying to make peace with the mostly damnable C++ language.
I have an application based on CFormView. From operator inputs thru edit controls, the View must access member functions of CDoc & CApp. My head is filled to confusion reading about scopes, statics, friends, and such. I couldn't get anything to work. I finally gave up and solved the problem.

//In CMyApp:
CMyApp* pApp; //declared at global level.
//Somewhere inside class construction:
pApp = this;

//In CFormView:
extern CMyApp* pApp;
//Any CMyApp member can be accessed now with:
pApp->MyAppMember();

This works so nicely that I'm sure I have violated some rules somewhere. How should I have done it correctly?
 
That's perfectly valid. However, it probably isn't the best way to be doing what you are doing. Typically you should be adding members to the document, view, and occasionally mainframe class and leaving the app class alone. Using globals in general can get especially messy, and should be avoided if possible. I know they created the global, but you should probably leave it alone unless you can't do something any other way. What is it that you are trying to accomplish, exactly?
 
TIMMAY3141--
I am using CApp to switch between multiple views in an SDI format. I found some sample code for this & it works nicely.
I have 5 primary views, each with 3-5 subpages. When a view changes, a matching structured control table must be selected.

CApp is only to switch the view. All other data interaction is between CFormView and CDoc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top