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.
aarsmade007Asked:
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.

Jaime OlivaresSoftware ArchitectCommented:
That should work... which error message? please be more specific.
hemakumarCommented:
Did u initialize the static varibale outside the class.Else it will give a linker error.

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
aarsmade007Author Commented:
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

Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Jaime OlivaresSoftware ArchitectCommented:
The problem is that you need to initialize static variables.

On you C1.cpp file initialize static variable:

CString CPage1::m_strSelectedFolder = "";
aarsmade007Author Commented:
Thanks, both. Apparently I initialized it on thw wrong place (OnInitDialog).
Now it works.
hemakumarCommented:
Initialize it as jaime said.
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.