Does it make sense for a last class deriving from a virtual base?

F

fl

Hi,
I am learning C++ of a web example of an open source library of TLM.
TLM is accepted in the industry. I suppose it is dependable while the
example may be not because it is not an official document. I am new to
C++ class.

In the example (see below), "select_initiator" is defined for the
application. The new class definition has a virtual class as its base
class.
I do not understand the reason for having virtual key word in the
definition. Can you tell me it is correct, or not?

From C++ books, an example is that both istream and ostream are
defined as virtual, so iostream does not have the ambiguty problem.
Here, I have a new question. What effects are if only one of istream
and ostream is defined as virtual while the other does not?





.............................
class select_initiator /// TLM AT
select_initiator
: public sc_core::sc_module /// inherit from
SC module base clase
, virtual public tlm::tlm_bw_transport_if<> /// inherit from
TLM "backward interface"
{
 
F

fl

Hi,
I am learning C++ of a web example of an open source library of TLM.
TLM is accepted in the industry. I suppose it is dependable while the
example may be not because it is not an official document. I am new to
C++ class.

In the example (see below), "select_initiator" is defined for the
application. The new class definition has a virtual class as its base
class.
I do not understand the reason for having virtual key word in the
definition. Can you tell me it is correct, or not?

From C++ books, an example is that both istream and ostream are
defined as virtual, so iostream does not have the ambiguty problem.
Here, I have a new question. What effects are if only one of istream
and ostream is defined as virtual while the other does not?

............................
class select_initiator                              /// TLM AT
select_initiator
:         public sc_core::sc_module                 /// inherit from
SC module base clase
, virtual public tlm::tlm_bw_transport_if<>         /// inherit from
TLM "backward interface"
{

Sorry, I miss Thanks to the potential helper in the above post.
 
M

Michael Doubez

Hi,
I am learning C++ of a web example of an open source library of TLM.
TLM is accepted in the industry. I suppose it is dependable while the
example may be not because it is not an official document. I am new to
C++ class.

In the example (see below), "select_initiator" is defined for the
application. The new class definition has a virtual class as its base
class.
I do not understand the reason for having virtual key word in the
definition. Can you tell me it is correct, or not?

I cannot because I don't know what you want to achieve.
On a general principle, virtual inheritance is used for solving the
diamond problem in multiple inheritance.
I suggest you to read about it.
From C++ books, an example is that both istream and ostream are
defined as virtual, so iostream does not have the ambiguty problem.

I don't understand what you mean. istream and ostream virtually
inherit from ios. iostream inherits from both iostream and ostream.
It is not a matter of ambiguity.
Here, I have a new question. What effects are if only one of istream
and ostream is defined as virtual while the other does not?

You mean what is the effect of:

class A{};

class B: public virtual A {};
class C: public A {};

class D: public B, public C {};

B, and C don't share a common A instance.
But in the following example:

class E: public virtual A {};
class F: public D, public E {};

E and B will share the same A instance.

[snip]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top