gkmike68 Posted May 14, 2015 Report Posted May 14, 2015 Hi All, I have a case using "diamond inheritance" sc_module as below figure base / \ A B \ / top 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? Thanks Quote
kartikkg Posted May 14, 2015 Report Posted May 14, 2015 Hi, You can try to inherit Class Base as virtual in Class A & Class B. Will that work for you ? Quote
gkmike68 Posted May 14, 2015 Author Report Posted May 14, 2015 Hi Kartik, Actually I did. I modified my question to make it clearer sorry for the mistake Quote
gkmike68 Posted May 15, 2015 Author Report Posted May 15, 2015 Hi All, I solved this problem by using only one sc_module base=> struct to share A and B A => normal c++ class B => normal c++ class top=> a systemc module (virtual public A, virtual public B ) SC_THREAD should be written in top only Quote
David Black Posted May 15, 2015 Report Posted May 15, 2015 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 Quote
Philipp A Hartmann Posted May 17, 2015 Report Posted May 17, 2015 As a final remark: No, you can't use sc_module as a virtual base class, not only due to the required casts to start/create the embedded SystemC processes. Your solution to split the implementation is correct. hth, Philipp Quote
Recommended Posts
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.