Repeated

Repeated inheritance example.

Summary
RepeatedRepeated inheritance example.
OverviewThe simplest and most obvious use of multiple inheritance is to “glue” not related classes together, as part of the implementation of a third class.
BaseBase class
Enumerations
ReturnValueReturn value enumeration
Functions
~BasePublic destructor
BasePublic constructor
ConstFunctionConst function returning a const value
ConstReturnFunction returning a const * const value
NothrowFunctionA nothrow function
ReturnValueFunctionA function with a typed return value
StaticFunctionStatic function returning a const value
ThrowFunctionA throw function
VectorFunctionA function returning a vector of ints
VirtualConstA const pure virtual function
DerivedADerivedA class
Functions
=Assigment operator
~DerivedAPublic destructor
DerivedAPublic constructor
DerivedBDerivedB class
Functions
=Assigment operator
~DerivedBPublic destructor
DerivedBPublic constructor
TopTop class
Functions
=Assigment operator
~TopPublic destructor
TopPublic constructor

Overview

The simplest and most obvious use of multiple inheritance is to “glue” not related classes together, as part of the implementation of a third class.

Example

void
main( void )
{
    DerivedA devivedA;
    Top top;
}

Output

Hello from Base 1
Hello from Derived A
Hello from Base 2
Hello from Derived A
Hello from Derived B
Hello from TOP 2
ByeBye from TOP
ByeBye from Derived B
ByeBye from Derived A
ByeBye from Base 2
ByeBye from Derived A
ByeBye from Base 1

Base

class Base

Base class

Summary
Enumerations
ReturnValueReturn value enumeration
Functions
~BasePublic destructor
BasePublic constructor
ConstFunctionConst function returning a const value
ConstReturnFunction returning a const * const value
NothrowFunctionA nothrow function
ReturnValueFunctionA function with a typed return value
StaticFunctionStatic function returning a const value
ThrowFunctionA throw function
VectorFunctionA function returning a vector of ints
VirtualConstA const pure virtual function

Enumerations

ReturnValue

enum ReturnValue {

Return value enumeration

ONEenum one .
TWOenum two
THREEenum three enum three cont
FOURenum fourenum four count

Functions

~Base

~Base()

Public destructor

Base

Base(int data)

Public constructor

Parameters

dataan integer

ConstFunction

unsigned ConstFunction() const

Const function returning a const value

ConstReturn

char const* const ConstReturn()

Function returning a const * const value

NothrowFunction

int NothrowFunction() throw()

A nothrow function

ReturnValueFunction

Base::ReturnValue ReturnValueFunction()

A function with a typed return value

StaticFunction

const unsigned StaticFunction()

Static function returning a const value

ThrowFunction

int ThrowFunction() throw(A, B)

A throw function

VectorFunction

const std::vector<int> & VectorFunction()

A function returning a vector of ints

VirtualConst

void VirtualConst() const = 0

A const pure virtual function

DerivedA

class DerivedA : virtual public Base

DerivedA class

Summary
Functions
=Assigment operator
~DerivedAPublic destructor
DerivedAPublic constructor

Functions

=

DerivedA& operator=(const DerivedA&)

Assigment operator

~DerivedA

~DerivedA()

Public destructor

DerivedA

DerivedA()

Public constructor

DerivedB

class DerivedB : virtual public Base

DerivedB class

Summary
Functions
=Assigment operator
~DerivedBPublic destructor
DerivedBPublic constructor

Functions

=

DerivedB& operator=(const DerivedB&)

Assigment operator

~DerivedB

~DerivedB()

Public destructor

DerivedB

DerivedB()

Public constructor

Top

class Top : public DerivedA, public DerivedB

Top class

Summary
Functions
=Assigment operator
~TopPublic destructor
TopPublic constructor

Functions

=

Base& Base::operator=(const Base&)

Assigment operator

~Top

Public destructor

Top

Public constructor

To send feedback on this topic email: natural.nosp@m.docsplus@gmai.nosp@m.l.com

© Some Rights Reserved. see <License>

class Base
Base class
enum ReturnValue {
Return value enumeration
~Base()
Public destructor
Base(int data)
Public constructor
unsigned ConstFunction() const
Const function returning a const value
char const* const ConstReturn()
Function returning a const * const value
int NothrowFunction() throw()
A nothrow function
Base::ReturnValue ReturnValueFunction()
A function with a typed return value
const unsigned StaticFunction()
Static function returning a const value
int ThrowFunction() throw(A, B)
A throw function
const std::vector<int> & VectorFunction()
A function returning a vector of ints
void VirtualConst() const = 0
A const pure virtual function
class DerivedA : virtual public Base
DerivedA class
DerivedA& operator=(const DerivedA&)
Assigment operator
~DerivedA()
Public destructor
DerivedA()
Public constructor
class DerivedB : virtual public Base
DerivedB class
DerivedB& operator=(const DerivedB&)
Assigment operator
~DerivedB()
Public destructor
DerivedB()
Public constructor
class Top : public DerivedA, public DerivedB
Top class
Base& Base::operator=(const Base&)
Assigment operator