Jump to content

is it possible to use "virtual public sc_module"?


Recommended Posts

Hi All,


I have a case using "diamond inheritance" sc_module as below figure



   /      \

 A       B

   \       /



base=> struct to share A and B

A => a systemc module (virtual public sc_module)

B => a systemc module (virtual public sc_module)

top=> a systemc module (virtual public A, virtual public B )


it work fine.


But when I using SC_THREAD. 


the compiler shows error, "pointer to member conversion via virtual base".


is it possible to fix the error?



Link to comment
Share on other sites

It looks like you solved your problem; however, just a C++ note as to using of the keyword 'virtual' with classes and the infamous diamond problem.

// Example demonstrating proper use virtual class inheritance to solve the dreaded diamond problem.
// Only a problem when base class contains data.
#include <iostream>
#include <systemc>

struct Base { int m_i; Base():m_i(42){} };

// Only one of the following two required to use 'virtual' keyword, but two is safer
struct A : virtual Base { int m_a; A(): m_a(1){} };
struct B : virtual Base { int m_b; B(): m_b(2){} };

// The following will only have one copy of 'var' from Base
struct Final: A, B
  Final() { std::cout << "Constructed Final with m_i=" << m_i << std::endl; }

int sc_main(int argc, char* argv[]) {
  Final f;
  sc_assert( f.m_i == 42 );
  return 0;
// Copyright 2015 by David Black
// License: Apache 2.0
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...