|
-
August 17th, 2002, 05:54 PM
#1
question about static member
when I define some classes like following:
class Base
{
public:
Base(){cout<<"come from Base";}
};
class COk
{
public:
Base _base;
};
there can be a string displayed which proved the _base object can be initialized.but when I add static in it:
class Base
{
public:
Base(){cout<<"come from Base";}
};
class COk
{
public:
static Base _base;
};
nothing displayed,
First, I want to ask why? I know when a member in a class marked static, there will be only one copy kept even if the class produced many objects.but why the initializtion cann't carry out?please give me explaination on how compiler reacts when meet static object in a class or show me relevant articles to refer.thank you in advance.
The next question is How can I carry out the initialization of a static member?
my program followed:
#include<iostream.h>
class Base
{
public:
Base(){cout<<"come from Base";}
};
class COk
{
public:
static Base _base;//the static here make difference.
};
COk _myCok;
void main()
{}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|