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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about classes...problem...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
i have 2 classes...one is called ClassOne, the other is ClassTwo...ClassTwo has a member variable in it called m_nVariable. I tried to access that member variable from ClassOne by using this code:

void ClassOne::OnButton1()
{
ClassTwo* mem;
CString string;

string.Format ("%d", mem.m_nVariable);
AfxMessageBox (string);
}

this code compiles ok, but it still won't display m_nVariable....I just get a blank message box...wut could the problem be??
 
> wut could the problem be??

There is a loose nut between your keyboard and your chair LOL

But seriously,

> ClassTwo* mem;
then
> mem.m_nVariable

First you declare 'mem' as a pointer type and do not initialize it (VERY BAD) %-(

Next you address the pointer 'mem' using reference notation '.' instead of pointer notation '->', i.e.:

mem->m_nVariable

Hope this helps
-pete

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top