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.
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"
neither of the two worked.
so, if I prefer not to declare aaa global, how should I access aaa from C2 ??
Thanks in advance.
That should work... which error message? please be more specific.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
when it is static it says:
Page1.obj : error LNK2001: unresolved external symbol "public: static class CString CPage1::m_strSelectedFolde r" (?m_strSelectedFolder@CPag e1@@2VCStr ing@@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_strSelectedFolde r" (?m_strSelectedFolder@CPag e1@@2VCStr ing@@A)
Page1.obj : error LNK2001: unresolved external symbol "public: static class CString CPage1::m_strSelectedFolde r" (?m_strSelectedFolder@CPag e1@@2VCStr ing@@A)
Release/_UI_2_.exe : fatal error LNK1120: 1 unresolved externals
Page1.obj : error LNK2001: unresolved external symbol "public: static class CString CPage1::m_strSelectedFolde
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_strSelectedFolde
Page1.obj : error LNK2001: unresolved external symbol "public: static class CString CPage1::m_strSelectedFolde
Release/_UI_2_.exe : fatal error LNK1120: 1 unresolved externals
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, both. Apparently I initialized it on thw wrong place (OnInitDialog).
Now it works.
Now it works.
Initialize it as jaime said.