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

why does a class declaration include private members?

P: n/a
Hi all,

I was just wondering why a class declaration also includes the private
members of a class. Is this information needed by other classes for
compiling and/or linking or is this just an historical issue?
I can see why subtypes and friends need this information but what about
other related classes.
I would imagine that by declaring the members in a source file or at least
in another header file the 'public' header file would be more fit for the
role of abstract interface.

Corno
Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Corno wrote:
Hi all,

I was just wondering why a class declaration also includes the private
members of a class. Is this information needed by other classes for
compiling and/or linking or is this just an historical issue?
Where would you put them instead? A second declaration for the private
part of the class? What about protected members? A third declaration?
I can see why subtypes and friends need this information but what
about other related classes.
I would imagine that by declaring the members in a source file or at
least in another header file the 'public' header file would be more
fit for the role of abstract interface.


It not only needed for subtypes and friends. Even parts of your code
that only use the public iterface need it. How else could e.g. a
function allocate the needed space for a local variable, if it doesn't
know the size of the class?

Jul 19 '05 #2

P: n/a
"Corno" <corno@%spam%.dds.nl> wrote in message
news:bg**********@news.tudelft.nl...
Hi all,

I was just wondering why a class declaration also includes the private
members of a class. Is this information needed by other classes for
compiling and/or linking or is this just an historical issue?
A private declaration is just an access-restriction for the program, it
does not hide information. The compiler sees and requires private
members in exactly the same way as it sees and requires public
members.
I can see why subtypes and friends need this information but what about
other related classes.
I would imagine that by declaring the members in a source file or at least
in another header file the 'public' header file would be more fit for the
role of abstract interface.
Yes, abstract interfaces can be implemented in C++ by using a so called
"Pimpl-idiom", see http://www.gotw.ca/gotw/024.htm
Corno

Jul 19 '05 #3

P: n/a

"Rolf Magnus" <ra******@t-online.de> wrote in message
news:bg*************@news.t-online.com...
Corno wrote:
Hi all,

I was just wondering why a class declaration also includes the private
members of a class. Is this information needed by other classes for
compiling and/or linking or is this just an historical issue?


Where would you put them instead? A second declaration for the private
part of the class? What about protected members? A third declaration?
I can see why subtypes and friends need this information but what
about other related classes.
I would imagine that by declaring the members in a source file or at
least in another header file the 'public' header file would be more
fit for the role of abstract interface.


It not only needed for subtypes and friends. Even parts of your code
that only use the public iterface need it. How else could e.g. a
function allocate the needed space for a local variable, if it doesn't
know the size of the class?

Good point :)
Overlooked that obvious one!

Thanx,

Corno
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.