static member in base class

T

t

Lippman's C++ Primer says that if a base class defines a static data
member or method, then there is only one such member for the
inheritance hierarchy rooted at the base class.

So no matter how many objects exist in the hierarchy, they all share
the same static members? How does this work? Do they all have method
pointers all pointing to the same set of static members?

Are static members created when a program is first run and placed in a
special section of memory? I am curious about how C++ implements
things, but I never studied comp sci beyond introductory classes.
 
T

t

So no matter how many objects exist in the hierarchy, they all share
the same static members? How does this work? Do they all have method
pointers all pointing to the same set of static members?

I meant to say "Do they all have pointers...."
 
V

Victor Bazarov

t said:
I meant to say "Do they all have pointers...."

You would probably benefit from reading "Inside the C++ Object Model"
by Stanley Lippman. You seem to want to know how things work on the
inside, and that's a decent book to answer your questions.

Meanwhile, imagine that static members are just glorified globals.
The essential (the only real) difference with namespace globals is
that the names of class static data members are declared to have
access specifiers.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top