Questions tagged [private-inheritance]

Private inheritance is a form of inheritance is which the public and protected portion of the base class becomes private in the derived class and the derived class has no access to the private members and methods of the base class.

63 questions
1
vote
1 answer

why name publicizing is there when we want to inherit the base class privately?

Generally, we wish to use private inheritance to hide the implementation details to the base class. If this is true, 1) Why is the name publicizing feature is there again ? Is it only for language completeness or is there any practical usage…
1
vote
1 answer

typecast operator in private base

I found something I consider strange behaviour in C++: a typecast operator in a private base class is confusing the compiler when trying to resolve an implicit cast: #include struct Base { #ifdef ENABLE operator bool () const { return…
1
vote
1 answer

Object slicing in private inheritance

Why object slicing does not takes place in private inheritance? Static_cast gives error in such cases? I understand that the private inheritance does not hold “is - a” relationship between its inheritance classes. Does this has something to do with…
Bhupesh Pant
  • 4,053
  • 5
  • 45
  • 70
1
vote
1 answer

need design help using private inheritance

I have a problem with the following situation: a library (CardReader) implements the ISO7816 protocol and communicates with a smart card (implemented by me). I have to implement a proprietary protocol that use this library. In CardReader there are…
Elvis Dukaj
  • 7,142
  • 12
  • 43
  • 85
0
votes
4 answers

Why does private inheritance increase the probability, as compared to composition, that someone will break my code?

The author of this article states that "Normally you don't want to have access to the internals of too many other classes, and private inheritance gives you some of this extra power (and responsibility). But private inheritance isn't evil; it's just…
Belloc
  • 6,318
  • 3
  • 22
  • 52
0
votes
2 answers

Why does C++ allow this pointer polymorphism of private parent?

If I inherit a derived class privately from a base class, I cannot get the polymorphism of the inhritetted class. But I can get the polymorphism of 'this' pointer inside the derived class. I'm very curious about why 'this' pointer is allowed to…
sake
  • 387
  • 4
  • 12
0
votes
0 answers

Can I pull all members of a private base into the public scope of an inheriting class?

When inheriting privately from a base class, I can say public: using Base::member; to make that (non-private) member public within the inheriting class. Is there some way to expand this to get all the members at once? The context I want this in is a…
bitmask
  • 32,434
  • 14
  • 99
  • 159
0
votes
0 answers

Bringing privately inherited Base`s class constructor to the Derived's public scope

Inheriting a constructor from a private template class in C++ explaining that by using Base::Base; inside Derived we're bringing the type Base injected in Base as Base::Base to scope of Derived and not actual Base's c-tor(s). I'm intersting in whys…
Soup Endless
  • 439
  • 3
  • 10
0
votes
1 answer

C++ How can you Point to a Private Inherited Class Object Within a Class

I am learning about class inheritance and I wanted to know how one can create a pointer to a class that was inherited privately by another class? I've included a simple example below. Many thanks to those who help in answering this question. class…
0
votes
1 answer

upcasting to interface with private inheritance

I have the following situation class Interface { }; class ComplicatedObject : public Interface { }; and I would like to give a simplified version of the ComplicatedObject, still providing the Interface. I was thinking to private inheritance, such…
Teloze
  • 279
  • 2
  • 8
0
votes
1 answer

Overriding a publically aliased method via private inheritance

I have a class heirarchy where there is one base type Base with a list of implementations and another base class, AnotherBase, that is almost like Base but a little different. To express this in the language I used private inheritance on the second…
Curious
  • 20,870
  • 8
  • 61
  • 146
0
votes
1 answer

Can I omit non-public inheritance for forward-declaration of classes?

Let's say I have a piece of code like this: // Foo.h: class Incomplete; // the forward-declaration class Foo { void bar(Incomplete&); // doesn't really matter }; // Foo.cpp: class Incomplete : private Baz { }; void Foo::bar(Incomplete&) { } Is…
0
votes
4 answers

Private inheritance usage as described in "The C++ Programming Language"

In The C++ Programming Language, 4th Edition, at §20.5.2 "Access to Base Class" (page 605), it says (regarding private inheritance): private bases are most useful when defining a class by restricting the interface to a base so that stronger…
yonutix
  • 1,964
  • 1
  • 22
  • 51
0
votes
2 answers

How to cast to privately derived child type?

The following is an attempt at implementing a shared pointer with a modified semantics of operator==: template struct deref_shared_ptr: private std::shared_ptr { using Base = std::shared_ptr; // ... using statements to…
AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68
0
votes
1 answer

How best to expose private inheritance to base class?

I am designing an object hierarchy in which the base class of all objects is Node, which is expected to be subclassed. Subclasses of Node will contain child items, but the type of child can vary from one subclass to another. I am implementing…
Carlton
  • 4,217
  • 2
  • 24
  • 40