473,505 Members | 13,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

the essense of the static data member of a class

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
1 3144
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
4361
by: Alexander Mahr | last post by:
Dear Newsgroup, I'm somehow confused with the usage of the static keyword. I can see two function of the keyword static in conjunction with a data member of a class. 1. The data member...
11
4572
by: Roger Leigh | last post by:
The C++ book I have to hand (Liberty and Horvath, Teach yourself C++ for Linux in 21 Days--I know there are better) states that "static member functions cannot access any non-static member...
8
1815
by: SJ | last post by:
Hi: I have a class which has a static member function. The function implements something common to all instances. How can the static member function know all of the (Get access to the instances'...
3
3582
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
8
4561
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
14
2842
by: Mike Hewson | last post by:
Have been researching as to why: <example 1> class ABC { static const float some_float = 3.3f; }; <end example 1>
6
2457
by: lovecreatesbeauty | last post by:
Hello Experts, Why static data members can be declared as the type of class which it belongs to? Inside a class, non-static data members such as pointers and references can be declared as...
1
2266
by: Frederiek | last post by:
Hi, When modifying a data member in a class declaration, the static keyword specifies that one copy of the member is shared by all instances of the class. Does that mean that the address of...
15
7839
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.