Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can't Access Application Class data members.

Posted on 1998-11-25
4
Medium Priority
?
171 Views
Last Modified: 2013-11-20
Hi,
I have and SDI application. I have declared few public
variables to the Application Class as well as MainFrame class.

How do I access these variables from a new class created
by me? When I used AfxMainWnd()-> or AfxGetApp()->
it gave the following errors respectively.
error C2039: 'EntityFileName' : is not a member of 'CWnd'
error C2039: 'EntityFileName' : is not a member of 'CWinApp'

I had declared 'EntityFileName' as a Cstring in the respective classes. Is it that only base class members are
accessed using those functions?

What is the solution???
Thanks.
 
0
Comment
Question by:leena_mary
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 200 total points
ID: 1325270
You see, ::AfxGetApp() returns a pointer to CWinApp class and not your own application class, which, let us say is called CMyApp
To get over this problem, you do the following:

CMyApp *m_pApp;
m_pApp=(CMyApp *)::AfxGetApp();
// access your variable now like m_pApp->EntityFileName
For the variable in the MainFrame class you could do something like this:
CMainFrame *m_pFrWnd=::AfxGetApp()->m_pMainWnd;
//and then m_pFrWnd->EntityFileName

Hope this will sort your problem.
Thanks and best of luck.
pagladasu


0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1325271
Hi,
Just an afterthought. You can interact with all the classes in a Document-View application architecture.
The important thing is that most funtions will return a pointer to the base class. Since with a pointer to the base class, you can only access the base class members even if you make it point to a derived class object. The only way it helps is in implementing run time polymorphism. If you want this pointer to access derived class members also, you must do an exclusive type-casting.
Hope this will clear up your doubts. Any other queries, feel free to clarify them. My email address is:
espical@hotmail.com
Thanks.
pagladasu.
0
 

Author Comment

by:leena_mary
ID: 1325272
Thanks, pagladasu.

0
 

Author Comment

by:leena_mary
ID: 1325273
Thanks, pagladasu.

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question