Skip to main content

All Questions

Tagged with
0 votes
1 answer
69 views

How to use virtual function in the base class?

Consider the following two structures: struct Potential{ virtual double energy(int full_system, int particle_id)=0; double energy(int full_system){ int n_particles=100; double ...
Botond's user avatar
  • 2,772
4 votes
1 answer
91 views

Why can't C++ using-declaration expose a protected member of base as a public member of derived?

As per cppref: Using-declaration introduces a member of a base class into the derived class definition, such as to expose a protected member of base as public member of derived. However, the ...
xmllmx's user avatar
  • 41.2k
0 votes
1 answer
33 views

enable_if for templated base class (C++11) meta-programming

I have tried writing a program that behaves something like "compile-time inheritance" for example the following C++11 meta-program ... // imports #include <type_traits> // non-...
FJ W's user avatar
  • 1
-1 votes
1 answer
73 views

Confusion around pointers management for composite pattern with inheritance

I'm designing a module to determine if a Point is inside/outside some boundaries defined by geometric objects. In order to do this, I have the following base class : #pragma once #include "Point....
IEatBagels's user avatar
0 votes
0 answers
61 views

How can I pass by reference considering inheritance?

Here's my scenario (notice the code I can edit, the code I cannot): #include <iostream> // the follow is untouchable (from sdk) struct Base { }; template <class TParamQuantity = Base> ...
markzzz's user avatar
  • 47.4k
0 votes
1 answer
28 views

How can I access a protected variable in child class through an abstract class pointer?

I have an abstract class that I have derived from two child classes. One of them has a protected variable that the other one does not. To make the code more general, I have to use an smart pointer of ...
Amin mosayyebzadeh's user avatar
2 votes
1 answer
184 views

How do I make Class A a member of Class B without inheriting it?

I have two classes (actually four, but they're not required for this). Let's call them A, and B. I am trying to declare class B as a member in class A. My problem is, I need access to a member ...
ConfusedCoder's user avatar
0 votes
4 answers
65 views

When inheriting a Base class privately, can I declare the Base classes Basse class public?

I have a class "SuperBase" with public methods and a class "Base", that derives from SuperBase, also with public methods. I cannot alter these, as they come from an external ...
GulaschLulatsch's user avatar
2 votes
3 answers
392 views

Child class invoking parent copy assignment instead of move assignment?

Hi i wrote the code bellow, I have a parent class (Vehicule) and a child class (Car), i'm trying to study the behavior of Move/Copy assignment with inheritance. However there is something i don't ...
ASMCoder's user avatar
-1 votes
1 answer
47 views

How to Store and retrieve the the correct Type of DerivedClass Pointer To/From Map of BaseClass Pointer

Hello i have question about Maps and Inheritance. I have Map of BaseClass Pointer: std::map<int,std::shared_ptr<Game>> GamesByID; and inserted Derived Class Pointer into it like: GamesByID....
Rokrait's user avatar
  • 31
1 vote
0 answers
63 views

C++: derived structure layout and copiability

I have the following structs #pragma pack(push) struct COMMON { uint16_t type; uint16_t m; uint16_t o; uint16_t f; uint64_t s; }; #pragma pack(pop) #pragma pack(push) struct ...
MaPo's user avatar
  • 683
1 vote
2 answers
861 views

How to test a protected member from multiple inheritance in GoogleTest?

Imagine I have a Foo class which contains a protected member. Foo is my template base class. Then I have a Bar class, which inherits from Foo. The protected member will be private within Bar. I need ...
waas1919's user avatar
  • 2,535
0 votes
4 answers
620 views

C++ Child Class Change Parent Class's Constructor

Modified the question a bit, thanks for your help on this! Is there a way to change Parent's constructor(e.g. change the value of protected field) when initialize the Child class. For example, I have ...
PepperGooooo's user avatar
1 vote
1 answer
117 views

How to solve the problem that the subclass inherits the base class and meanwhile the base class is a template parameter

#include <iostream> using namespace std; template <typename Child> struct Base { void interface() { static_cast<Child*>(this)->implementation(); } };...
asele's user avatar
  • 52
1 vote
2 answers
458 views

"If the deriving class does not inherit the base class virtually, then all virtual methods must be defined".How to understand that in the right way?

As per the wiki, which says that[emphasise mine]: Note the code snippet in the quotaion is seen here. Suppose a pure virtual method is defined in the base class. If a deriving class inherits the base ...
John's user avatar
  • 3,348

15 30 50 per page
1
2 3 4 5
42