[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: why this program can be compiled, but cannot be linked?
From: |
Larry I Smith |
Subject: |
Re: why this program can be compiled, but cannot be linked? |
Date: |
Fri, 29 Apr 2005 19:55:08 GMT |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.7) Gecko/20050414 |
Andy wrote:
> Hi,
>
> I just write a small program on nested class. It can be compiled, but
> cannot be linked. How shall I solve this problem? The program is as
> follows:
>
> #include <iostream>
> #include <string>
> using namespace std;
>
> class A{
> public:
// declare the static member A::str
> static string str;
>
> class B{
> public:
> void method(){ str = "assigned in class B"; }
> };
>
> class B b;
> };
>
// define static member A::str;
string A::str;
> int main()
> {
> A a;
> a.b.method();
> cout<<"a.str = "<<A::str<<endl;
> }
>
> Thanks a lot!
>
> Andy
>
See the changes above.
Regards,
Larry
--
Anti-spam address, change each 'X' to '.' to reply directly.