Link to home
Start Free TrialLog in
Avatar of aarsmade007
aarsmade007

asked on

basic classes question

I have a class C1 with CString aaa (public)
I have a class C2 which needs to display aaa.

I tried the following:
1/
include C1.h in my C2 implementation file
declare aaa static (since it is allways the same once it is set by a function of C1)
from in C2: MessageBox(C1::aaa,"eee",0);
this gave error:

2/
C1 first;
C2 second;
C1.aaa="test";
from in C2: MessageBox(first.aaa,"eee",0);

neither of the two worked.

so, if I prefer not to declare aaa global, how should I access aaa from C2 ??

Thanks in advance.
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

That should work... which error message? please be more specific.
ASKER CERTIFIED SOLUTION
Avatar of hemakumar
hemakumar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aarsmade007
aarsmade007

ASKER

when it is static it says:
Page1.obj : error LNK2001: unresolved external symbol "public: static class CString CPage1::m_strSelectedFolder" (?m_strSelectedFolder@CPage1@@2VCString@@A)
fatal error LNK1120: 1 unresolved externals

hemakumar, when I tried to declare it in OnInitDialog I had those errors (the same as above):
_UI_2_Dlg.obj : error LNK2001: unresolved external symbol "public: static class CString CPage1::m_strSelectedFolder" (?m_strSelectedFolder@CPage1@@2VCString@@A)
Page1.obj : error LNK2001: unresolved external symbol "public: static class CString CPage1::m_strSelectedFolder" (?m_strSelectedFolder@CPage1@@2VCString@@A)
Release/_UI_2_.exe : fatal error LNK1120: 1 unresolved externals

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, both. Apparently I initialized it on thw wrong place (OnInitDialog).
Now it works.
Initialize it as jaime said.