Tagged Questions
13
votes
5answers
422 views
Diamond-inheritance scenario compiles fine in G++, but produces warnings/errors in VC++/Eclipse
I have a base class 'Base', which is a pure virtual class:
class Base {
public:
virtual void A() = 0;
virtual void B() = 0;
virtual ~Base() { } // Eclipse complains that a class with ...
13
votes
8answers
1k views
When virtual inheritance IS a good design?
EDIT3: Please be sure to clearly understand what I am asking before answering (there are EDIT2 and lots of comments around). There are (or were) many answers which clearly show misunderstanding of the ...
11
votes
6answers
434 views
Why does virtual inheritance need to be specified in the middle of a diamond hierarchy?
I have diamond hierarchy of classes:
A
/ \
B C
\ /
D
To avoid two copies of A in D, we need to use virtual inheritance at B and C.
class A { };
class B: ...
9
votes
2answers
598 views
In C++, should I almost always use virtual inheritance?
I see from this entry that virtual inheritance adds sizeof(pointer) to an object's memory footprint. Other than that, are there any drawbacks to me just using virtual inheritance by default, and ...
8
votes
6answers
705 views
Where is the “virtual” keyword necessary in a complex multiple inheritance hierarchy?
I understand the basics of C++ virtual inheritance. However, I'm confused about where exactly I need to use the virtual keyword with a complex class hierarchy. For example, suppose I have the ...
8
votes
2answers
452 views
Multiple (diamond) inheritance compiles without “virtual”, but doesn't with
Given the following code (without virtual inheritance) :
class A
{
public:
virtual void f() = 0;
};
class B : public A
{
public:
virtual void f() {}
};
class C : public A
{
public:
...
8
votes
4answers
2k views
is virtual inheritance from pure abstract classes (interfaces) necessary
Why is it that in the code below the compiler complains that PureAbstractBase is an ambiguous base class of MultiplyInheritedClass? I realize I have two copies of the PureAbstractBase in ...
6
votes
4answers
1k views
Method resolution order in C++
Consider the following class hierarchy:
base class Object with a virtual method foo()
an arbitrary hierarchy with multiple inheritance (virtual and non-virtual); each class is a subtype of Object; ...
6
votes
6answers
2k views
C++ Multiple Virtual Inheritance vs. COM
The net is overflowing with explanations of the "dreaded diamond problem".
So is StackOverflow. I think I understand that bit, but I fail to translate that knowledge into comprehending something ...
5
votes
4answers
865 views
Ambiguity in multiple inheritance of interfaces in C++
I made a test code as following:
#include <iostream>
using namespace std;
#ifndef interface
#define interface struct
#endif
interface Base
{
virtual void funcBase() = 0;
};
interface ...
5
votes
3answers
199 views
Complex diamond issue: C++ virtual inheritance
I have a diamond problem which look like this:
__ A
/ |\
| B | \
v|/v v\|v \v
B2 B3 C
\v /v /
B4 /
\ /
D
I tried many way to make the best virtual ...
5
votes
2answers
388 views
c++ Virtual Inheritance and dreaded diamond
I am having a hard time with a dreaded diamon problem.
For a reminder, here is the classical class hierarchy of this problem:
B
/ \
C1 C2
\ /
D
To solve it, the standard solution ...
5
votes
5answers
174 views
using sister inheritance
let us suppose some (legacy) code, which cannot be touched, declare
struct B{
public:
void f(){}
};
and let us suppose to have
struct A{
public:
virtual void f()=0;
};
is it possible to ...
4
votes
2answers
248 views
Inherit from multiple partial implementations of an abstract base class?
Is it possible to have a number of partial implementations of an abstract interface, and then collect these partial implementations into a single concrete class by using multiple inheritence?
I have ...
4
votes
3answers
387 views
Is it a good convention to virtually inherit from pure virtual (interface) classes?
I often use pure virtual classes (interfaces) to reduce dependencies between implementations of different classes in my current project. It is not unusual for me to even have hierarchies in which I ...