By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,651 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,651 IT Pros & Developers. It's quick & easy.

the essense of the static data member of a class

P: n/a
A static data member can be of the same class type as that of which it
is a member. A nonstatic data member is restricted to being declared as
a pointer or a reference to an object of its class.

And I haved used the sizeof operator to test a class which has a static
data member, the class size is all the nonstatic data member except the
static data member.

In compiler's view, is the static data member constructed after the
whole class constructed??And is the static data member just a "global"
variable in the class scope???
In compiler's view, the static data member actually is not the class
member, is that true???

Jun 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
ma********@yahoo.com wrote:
A static data member can be of the same class type as that of which it
is a member. A nonstatic data member is restricted to being declared as
a pointer or a reference to an object of its class.
Correct.

And I haved used the sizeof operator to test a class which has a static
data member, the class size is all the nonstatic data member except the
static data member.
It should be *at least* the sum of sizes of all non-static member
variables. Compiler can add more storage for things like padding and
type information, etc.

In compiler's view, is the static data member constructed after the
whole class constructed??And is the static data member just a "global"
variable in the class scope???
What do you mean by "construct" here?

If you mean instantiating, then it is done at runtime. And classes
themselves can't be constructed.

If you mean by compiling, then you might want to read some
compiler-related literature. Usually a compilation consists of several
passes. So by the time the compiler needs to emit code for the static
member variable it has all it needs to know about the class.

And yes, static member variables are much like namespace-scope variables
(including global variables.) Compiler needs only to enforce a set of
access rules for the use of it elsewhere in the code.
In compiler's view, the static data member actually is not the class
member, is that true???


What do you mean? And why do you care?

Ben
Jun 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.