Pointers to class members

Say I have three classes.
CMyButton, CMyDialog, and CWhatEver.
CMyDialog has a member variable CPoint m_DlgPoint.
How would I retrieve the data in m_DlgPoint from either CMyButton or CWhatEver?
And then say I want to get a value stored in a member variable or function of CMyButton from CWhatEver?
and vice versa
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi !!
   Be a bit clear what are these classes i mean their base classes and what u want to assign from CMyButton class to CMyDialog class member.
assume U have three classes and U want to acces the memebr variable of each other then U can declare a friend function or
declare the object as global and use extern in other cpp files to access them
You should pay attention to one of the basic axioms of Object Oriented Programming, encapsulation.

Why do you need this value.

Do you want the CMyDialog to tell you where it is via a CPoint class object.

Then you might consider having a function like this:

BOOL CMyDialog::Location(CPoint& rPoint)
 BOOL success;

 // here you do some code to determien where this is, maybe somehting like :
 rPoint.x = curLocation.x;
 rPoint.y = curLocation.y

 // did we successfully find our location
 return success;

In this way, clients of CMyDialog need not know anything about the internal data of CMyDialog, but can still get the information they require
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.


 You have to be more specific in your question.
I will anyway guess.

Lets assume you have a dialog box of which CMyButton derived button is a member.

Coming to the CWhateverClass.
How is it related to the CDialog and CMyButton class?

Let me assume CWhateverClass object to be a member of CDialog.

class  CDialog::...
  CMyButton      m_BtnOk;
  CEdit          m_EditName;
  CWahteverClass m_WhatEver;


Then to get to get all accessible members of the CDialog Class the CMyButton class only has to do a GetParent()->m_MemberVariable.

Same for CWhatever object.

Now your problem was accessing CButtonClass members in CWhatever and CWhateverClass members in CButton.
Since both are unrelated tou can do it the following ways:

1. Provide interface functions to access the member function.
2. Pass the member function (if the value does not change like CWnd pointer) in the constructor of the class you need the member variable.
3. Make these variables as static variables. This is possible only in case of flags and such kind of variables and not for dynamic data which change from instance to instane.

Hope one of them is the required answer. If not give the proper hierarch and i will clear that.

Rick Schneewind
electrickAuthor Commented:
Please forgive me, I'm used to doing things in VB, where life is much simpler.
I'm getting the feeling that what I want to do, really can't be done in all cases. I thought that I had explained it.  I was looking for a "one size fits all" type function that would work in every case.
So maybe it's best to just ask this...Is it possible to get a pointer, or somehow access, a member or function of another class, no matter what the class types are, or how they are related?
If so, How? If not, then OK.
In VB if U create a class I believe its global to all the modules
so U can acces the class in all module
let me illustrate with example

lets assume we have a class which is defined in some file say AFile.h

class A


we have  aimplementation of this file AFile.h as AFile.cpp

int A::priFunc()

int A::proFunc()

int A::pubFunc()

now U want to access the members of this class in some other file say FileXYZ.cpp
then U have to include the file AFile.h
in the file FileXYZ.cpp
#include "AFile.h"
in some function of this FileXYZ
declare a object of class A
in some function suncXYZ of class XYZ
  A MyAObject;
//Access the member function by using dot operator
 MyAObject.pubFunc(); //This is OK
 MyAObject.priFunc(); //This will give U a problem since UR accessing private member function

U can use any C++ text which will explain these concepts easily
Hope this clears problem a bit

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.