Question on base class access spec. and constructor

  • Thread starter Thread starter yungman
  • Start date Start date
  • Tags Tags
    Base Class
Click For Summary

Discussion Overview

The discussion revolves around the necessity and implications of base class access specifications (private and protected) in C++, particularly in the context of class inheritance and constructors. Participants explore the reasons for using these access specifiers and the impact on class design and API visibility.

Discussion Character

  • Debate/contested
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • Some participants question the necessity of private and protected base class access specifications, arguing that public members of a base class can still be accessed directly by external programs.
  • Others propose that keeping base classes private allows for a cleaner API by restricting access to only the intended parts of the class, preventing external code from relying on the underlying implementation.
  • A participant suggests that using structs during development can help clarify the API before switching to classes with appropriate access specifications.
  • There is a discussion about the visibility of base class members when a derived class is included, with some asserting that private inheritance does not hide the base class from external access if the base class header is included elsewhere.
  • Concerns are raised about the effectiveness of private inheritance when external programs can still access public members of the base class directly.
  • Participants discuss the role of constructors in derived classes, particularly whether calling the base class constructor explicitly is merely a matter of convenience or if it serves a more significant purpose when arguments are required.
  • Examples are requested to illustrate the points being made, particularly regarding the implications of access specifications and constructor usage.

Areas of Agreement / Disagreement

Participants express differing views on the effectiveness and necessity of private and protected inheritance, with no consensus reached. The discussion remains unresolved regarding the practical implications of these access specifications and their impact on class design.

Contextual Notes

Some participants highlight limitations in understanding how access specifications interact with header file inclusions and the visibility of class members, indicating a need for clearer examples and explanations.

  • #31
jtbell said:
Not enough time. It was at the end of a two-semester course that wasn't a "C++ course" with the goal of teaching everything about C++. It was an "intro to programming" course that used C++. It included some topics that weren't strictly C++, e.g. analysis of different sorting techniques (I always did at least one "simple sort" along with quicksort), and linked lists (which was my excuse for introducing pointers).

Looking back at a PDF of my old textbook, I see that inheritance was in the very last chapter. I may even have used only the first part of that chapter, because I don't remember using the examples in the later parts of it.

I don't think I ever taught a course (physics or CS) in which I covered the entire textbook. I always had to omit or skim lightly over stuff in order to cover the foundations at a pace my students could handle. I wasn't at a school like MIT. :wink:
I hope what I studied is a lot more than introduction of CS. I worked more than what the book shows, I know for fact from my grandson that took a C++ class in junior college for one semester, they used the Gaddis book, they barely covered to chapter 11 BUT totally skipped chapter 9 on Pointers. That's the hardest chapter of the first 11 chapters! The rest of the 10 chapters are easy. It's only after chapter 11 that it gets a lot harder. They did nothing on OOP.

Even follow straight from the book is not hard, I learn so much more playing with your program, really get into the the Three Amigos ( Constructor, Copy Constructor and Assignment Operator)! If I only follow the book, I'd learn nothing. The 3 Amigos are quite hard, it might look easy at the beginning, but I feel they are even harder than pointers. Those shallow copy with pointers are tricky, remember I kept at it until I made it failed?

I always make up programs and practice that are much harder than in the book. If I finish chapter 15, I can really say I studied the book from cover to cover.

Thanks for all your help.
 
Technology news on Phys.org
  • #32
jbunniii said:
It's a big language, and huge when you include the standard library. At this point I doubt that there's anyone on earth, including Bjarne Stroustrup, who can claim to know the whole thing.

And it just keeps getting bigger. You can see this in the page counts for the various (draft) standards:

C++98: 748
C++11: 1310
C++14: 1354
C++17: 1572
C++20: 1829

One opening question I ask job applicants is to rate their C++ knowledge on a scale of 1 to 10. Based on my limited data sample, most strong candidates rate themselves as 7 or 8.

I've seldom heard anyone say 9 or 10 (nor would I rate own knowledge that high), and those that did were actually quite unknowledgeable but apparently failed to realize it.
Yeh, I am not trying to be the expert, I just want to know what is the minimum I have to study to reach a milestone. It's like how many semester to study for a college student on C++.
 
  • #33
yungman said:
I hope what I studied is a lot more than introduction of CS. I worked more than what the book shows, I know for fact from my grandson that took a C++ class in junior college for one semester,
One semester is not very long. One college where I taught for several years had a 3-quarter sequence, with the first quarter being C, and the second being C++ including classes. The third quarter was data structures and algorithms. Two quarters would be 20 weeks, about 33% longer than a semester.
 
  • #34
Mark44 said:
One semester is not very long. One college where I taught for several years had a 3-quarter sequence, with the first quarter being C, and the second being C++ including classes. The third quarter was data structures and algorithms. Two quarters would be 20 weeks, about 33% longer than a semester.
That sounds about right, like my grandson studied 10 chapters(skipping chapter on pointers), the book is 15 chapters, so it's like 50% more than a semester. Do you skip any topics? Data structure is in the complete book from chapter 16 to 20, but it's shorter chapters, so that should fit nicely in a quarter.
 
  • #35
yungman said:
Yeh, I am not trying to be the expert, I just want to know what is the minimum I have to study to reach a milestone. It's like how many semester to study for a college student on C++.
The best way to learn C++ beyond the basics is to use C++ by writing programs of your own, and/or modifying other people's programs, e.g. by adding new features.

Since you're working on your own as opposed to being employed in a software organization, a great way to proceed would be to find an interesting open source project. Make a local clone, read through the source code, look up stuff in books or online (cppreference is a good web site) until you understand how it works, then try adding some small features.

This way any future learning will be motivated by a specific need as opposed to just reading through an encyclopedic reference such as Stroustrup. In my experience, this is a much more efficient way to learn new language/library features than simply reading about them.
 
  • #36
jbunniii said:
The best way to learn C++ beyond the basics is to use C++ by writing programs of your own, and/or modifying other people's programs, e.g. by adding new features.

Since you're working on your own as opposed to being employed in a software organization, a great way to proceed would be to find an interesting open source project. Make a local clone, read through the source code, look up stuff in books or online (cppreference is a good web site) until you understand how it works, then try adding some small features.

This way any future learning will be motivated by a specific need as opposed to just reading through an encyclopedic reference such as Stroustrup. In my experience, this is a much more efficient way to learn new language/library features than simply reading about them.
Thanks for the suggestion, I'll look into that. Where do you find those open source projects?

I even thought about looking for a jr. programmer position in firmware type using my experience in hardware design. But the idea of committing to a full time job is kind of unthinkable. Too bad they don't have part time job like this. I don't even mind low wages, just not full time.

Yes, I want to do something with the things I learn, not keep learning and learning. I want to practice with what I learned. It is so dry learning chapter after chapter like in the last 6 months. I think at the minimum is to start on the gaming and graphic book by Gaddis, I looked at it a little, it doesn't sound like they need deep knowledge on C++ as they only talked about Class and Inheritance in the last chapter or two.

Thanks
 
  • #37
Source code for a fair share cooperative/open source projects is on github. Usually there is parent site possibly with forums, email, or some other communication format.

For example I worked for short while on rootkit hunter - rkhunter. It is coded in perl and is not very active, last update in 2018. In my experience too many of these projects are not actively supported.

Others, very few, become standard parts of Linux or building blocks for specialty tools. Cygwin is an example of this. It emulates Linux/UNIX and sits on the Windows runtime. So you get a UNIX interface for your windows box. It is free and is still open source.
 

Similar threads

  • · Replies 36 ·
2
Replies
36
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
6K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 35 ·
2
Replies
35
Views
4K
  • · Replies 36 ·
2
Replies
36
Views
3K
  • · Replies 31 ·
2
Replies
31
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 89 ·
3
Replies
89
Views
6K