Access between classes

D

Doug Chinnock

I have several pointers to classes in the header file for MainDoc:
-----------------
class MainDoc : public CDocument
{
protected: // create from serialization only
MainDoc();
DECLARE_DYNCREATE(MainDoc)

// Attributes
public:
CAView* m_AView; // Set in AView:
CBView* m_BView; // Set in BView:
CCView* m_CView; // Set in CView:

// Operations
public:
 
V

Victor Bazarov

Doug said:
I have several pointers to classes in the header file for MainDoc:

Are you sure it's not 'CMainDoc'?
{
protected: // create from serialization only
MainDoc();
DECLARE_DYNCREATE(MainDoc)

// Attributes
public:
CAView* m_AView; // Set in AView:
CBView* m_BView; // Set in BView:
CCView* m_CView; // Set in CView:

// Operations
public:
.
.
==========
These get initialized when the classes (of type CTreeView and CView) are
created:

Are you sure it's not 'MainDoc'? Seems in disagreement with the earlier
definition...
pDoc->m_AView = this;
==========
I can use these from classes CTreeView and CView:

This is not right (are you making it up as you go?), it probably is

pDoc->m_AView->...
==========
However when I try to use the same code from a CDialog class, I get the
error:

'GetDocument' is apparently a member of 'CTreeView' and 'CView' and _not_
a member of 'CDialog'.
=========

Is there a means of providing access to variables in MainDoc?

You need to request the address of your 'MainDoc' or 'CMainDoc' (whichever
is the correct one) and pass it to the function in 'CDialog' or wherever
you need it.

And if you'd like an audience that is familiar with (and willing to
discuss) MFC, try microsoft.public.vc.mfc

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,188
Messages
2,571,002
Members
47,591
Latest member
WoodrowBut

Latest Threads

Top