Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
1 answer
349 views

What's the problem(s) with overriding a method with different access in base vs derived class

PC-Lint issues a warning when a method is overriden in a derived class with access specifier other than what is the inherited access. For example class B { public: virtual void fubar(void); }; ...
skyking's user avatar
  • 14.4k
1 vote
1 answer
760 views

What will happen when a class inherits a public method with reference to private properties?

I defined private properties hp and atk for warrior class and supposed that they won't be inherited by derived classes. In the following code, however, The derived class knight inherits a public ...
Bubble's user avatar
  • 23
0 votes
0 answers
116 views

How do you add private members of one class to an array of a different class

I am relatively new to c++ and I have just learned how to use an array in a class, but I can't figure out how to add private members of one class to an array of a different class. I have a base class ...
SwiftTurtle's user avatar
11 votes
2 answers
347 views

Exposing private base class name with `using` in C++

In a situation when some struct D inherits another struct A twice: once privately via B and the second time publicly via C, is it allowed to write using B::A in D? struct A {}; class B : A {}; struct ...
Fedor's user avatar
  • 22.4k
2 votes
0 answers
289 views

Member function of (public) derived class is inaccessible from main

I have four classes (classic diamond problem in C++). Let's call the grandparent class A, the parent classes B and C and the child class D. Both B and C have a public member function called attack. I ...
kubo's user avatar
  • 231
0 votes
1 answer
114 views

c++: private inheritance ambiguous call [duplicate]

In the code below the public method Base2::f() is expected to become a private member of the Derived class however the compiler complains about ambiguity. The question is on the basic understanding of ...
TruLa's user avatar
  • 1,145
1 vote
1 answer
1k views

Why can a C++ template class access a private member of its base class?

With Visual Studio 2019 (v 16.7.3), I have found that a template class can access the private members of it non-template base class. Is this an expected behavior or is it a compiler bug? When the ...
Jan Hettich's user avatar
  • 9,936
1 vote
1 answer
82 views

Can I forbid calling private member of derived class from base?

I has this code: struct A { virtual void f() {} }; struct B: A { private: void f() override {} }; ... B b; A& a = b; a.f(); And ofcourse it will call f() from B cause private is checked on ...
dasfex's user avatar
  • 1,320
1 vote
2 answers
349 views

Can't construct from std::initializer_list when privately inheriting from std::array

I'm trying to make a wrapper of std::array to perform boundary checks as suggested by this answer. This is the code I have: template <typename T, size_t N> class Array : private std::array<T,...
gustavo's user avatar
  • 13
1 vote
1 answer
68 views

private member vs private ineritance

I have a class A that I can not edit: class A{ public: int thisCoolFuntion(){ return 0; } }; I want to create a class that uses thisCoolFuntion() (let's call it class B or C) I want ...
Ivan's user avatar
  • 1,485
0 votes
2 answers
78 views

C++ inheritance private members

I have a question about inheritance: For example I have a base class A with private members: x, y I have getter functions getx and gety, I want to use the getter functions from A to class B that ...
abababa's user avatar
  • 49
14 votes
3 answers
281 views

C++: How to prevent private names from polluting derived types?

I was shocked today by the fact that this code snippet has an ambiguous name reference: class A { private: typedef int Type; }; class B { public: typedef int Type; }; class D : A, B { ...
zwhconst's user avatar
  • 1,563
-1 votes
1 answer
122 views

Inheritance/Polymorphism - Am I forced to use "protected" variables?

I am currently working with Big C++ 2nd Edition, using Code::Blocks 17.12, on the chapter for inheritance The book introduces the protected variable type for cases in which you want to allow a ...
Narish's user avatar
  • 759
-5 votes
3 answers
49 views

How private data member is used by an inherited class object?

Do private members are also inherited? Why get() function was able to read variable n #include <iostream> using namespace std; class base { int n; public: void get() { cin &...
user avatar
0 votes
2 answers
67 views

How to access the function in base class when using singleton class as a derived class

It is a header of generator class; #ifndef GENERATOR_H #define GENERATOR_H class Generator { public: Generator(int); ~Generator(); int getBits(); private: ...
Gideok Seong's user avatar

15 30 50 per page
1
2 3 4 5