Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reason for Private part os the class definition

Posted on 1997-12-09
2
Medium Priority
?
208 Views
Last Modified: 2010-04-10
Since the the private part of the class is not accessible by the clients, why must its parts be listed within the class definition. I need to answer to my students :WHY MUST I LIST THE PRIVATE PARTS OF THE CLASS SINCE THESE ARE NOT ACCESSIBLE BY THE CLIENTS? I OTHER WORDS, WHY NOT JUST FORGET ABOUT LISTING THEM? -- THE CLIENT DOES NOT NEED THEM ANYWAY. WHY MUST THESE DEFINITIONS MUST APPEAR WITHIN THE CLASS DEFINITION? I am looking for a short explanation and not code examples? I know the definition must be there, what I need to know is WHY?
0
Comment
Question by:josey
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1175619
answer comming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1175620
The simple answer:
To make life easy for the programmers who implement (write) the c++ compilers.

The longer answer:
When an object is created the compiler must create the entire class, that is, it must allocate and initialize all of the class (all data members, not just public ones).  Although client code cannot fool with a class's private data it does need to initialize it and it does need to know that it is there so that it knows how big a class is.  Now it would be possible to get around this.  A language could produce two versions of a class definition.  One for client's to "know" about.  And one for the compiler and class designer to use.  But that's more work for the language writters.  C++ was written by one overworked man who didn't do anything he didn't have to do.

I hope this helps.  I'm partial to using code examples.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question