Click to See Complete Forum and Search --> : how can I get a member variable from another class


Danielle Harvey
July 2nd, 1999, 10:37 PM
I have the following setup:

CHudForm::DoPrint()
{ UpdateData(TRUE);
extern void PrintForm1(CPage* pPage);
PrintForm1(ps);
delete ps;
}



and then the function PrintForm1 in a separate file has the structure;

void PrintForm1()
{
}



How can I get a member variable from the CHudForm class? I tried setting up

void PrintForm1()
{ CHudForm vdlg;
vdlg.m_edit;
}



but this isn't getting the value. I don't understand how I can get a member variable from the class CHudForm. Any response any one can give me will be greatly appreciated.

ric
July 3rd, 1999, 04:16 AM
Try this:

CHudForm::m_member;

if this does not work try by making a member varialbe to your app class and get it by calling ((CMyApp*)AfxGetApp())->m_member

Danielle Harvey
July 3rd, 1999, 02:01 PM
The scope resolution operator only works for global variables. Calling;

((CMyApp*)AfxGetApp())->m_member



retrieved the program title. Do you know of any other commands which can retrieve a member variable from a class? I appreciate any response any one can give me.

July 3rd, 1999, 02:22 PM
Depends on which member of which class you are trying to get, but most cases the members of a class have get's and set's, somewhere in the inheritance tree.

direct access of a member would be Class->m_Member or Class.m_Member, only if the member had public access.

Hope this helps :)

Rudolf
July 5th, 1999, 04:37 AM
I'm not sure whether I understand Your problem.
Is it right that Your code compiles and runs without any problems and the only thing is, that m_edit stores the wrong value?
Then Your problem is, that it is not possible to get the member variables of a CLASS (unless they're static but that's another problem) but only of an OBJECT (or instance) of this class. Different objects of the same class may have different values in their member variables. As far as I can see You have an object of CHudForm with some data You want to access and so You create a new object (i.e. another one) to get the data.
In PrintForm1 You have to get access to the object that called it. A possible way to do this is to change PrintForm1 so that it takes a second parameter of the type CHudForm* hf and call PrintForm1(ps, this). Now hf->m_edit should have the right value...
HTH
Rudolf