473,394 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

why does a class declaration include private members?

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
3 3922
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
"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

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

Similar topics

6
by: Chris Mantoulidis | last post by:
Forgive me if I'm wrong but I think there is something like an extra member scope in classes. for example: class abc { ostream & operator << (ostream &, const abc &); istream & operator >>...
3
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...
5
by: Walt Karas | last post by:
Is this code legal under the standard? struct A { int i; struct C { unsigned offset_of_c(void) { return((unsigned) &(((A *) 0)->c)); }
3
by: Steven T. Hatton | last post by:
Sorry about the big code dump. I tried to get it down to the minimum required to demonstrate the problem. Although this is all done with GNU, I believe the problem I'm having may be more general. ...
8
by: Sim Smith | last post by:
This is the problem: I have to inherit a third party class file in my library. If I directly do it, I will have to ship the third party header files to my customers as well. I do not want to...
11
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
11
by: DrNoose | last post by:
Hi! I've got a program that's almost done, but I'm getting compile errors in two lines: 317 & 319. I think the main error has to do with the Truck Class. I'm a newbie and keep looking at the...
3
by: pkolinko | last post by:
Hi everyone, I am writing a small low level embedded USB application using C++/CLI windows Forms. I am sort of new to the C++/CLI and having trouble understanding what happens in this very...
4
by: zfareed | last post by:
#include <iostream> #include <fstream> using namespace std; template<class ItemType> class SortedList { private:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.