SumitK

sc_module_name parameter for your constructor is required error

6 posts in this topic

Hi

With the following code, I am getting the error "Error: (E513) an sc_module_name parameter for your constructor is required"

I am not able to understand why ?

Can anyone help please

#include <iostream>
#include <systemc.h>

using namespace std;

class Foo: public virtual sc_module
{
    public:
    Foo(sc_module_name val) { }
};

class Bar : public virtual sc_module
{
    public:
    Bar(sc_module_name name) : foo(name) { }
    Foo foo;
};

int sc_main(int argc, char* argv[]){
    Bar b("b");
    sc_start();
    return 0;
}

Thanks

Sumit

Share this post


Link to post
Share on other sites

Hey try this alternative solution, its working for me



class Bar : public virtual sc_module
{
    Foo foo;
    public:
    Bar(sc_module_name a) : foo((const char*)(a)) {    }
 
};

I wonder why your solution is not working even though the base class  overloaded with sc_module_name parameter constructor

Share this post


Link to post
Share on other sites

Hi,

You have to forward the module name to the base class constructor:

foo(sc_core::sc_module_name name) 
: sc_module(name)
{}

Or use SC_CTOR instead.

Greetings

Ralph

Share this post


Link to post
Share on other sites

Hi Ralph

I tried as you suggested(see below). I still have the same issue.

#include <iostream>
#include <systemc.h>

using namespace std;

class Foo: public virtual sc_module
{
    public:
    Foo(sc_module_name name):sc_module(name) { }
};

class Bar : public virtual sc_module
{
    public:
    Foo foo;
    Bar(sc_module_name name) : foo(name) { }
};

int sc_main(int argc, char* argv[]){
    Bar b("b");
    sc_start();
    return 0;
}

Thanks

Sumit

Share this post


Link to post
Share on other sites

Hi Sumit.

what you are doing here is a hierarchical module. foo is a member, i.e. a submodule of bar. They should not have the same name.

If you want bar to be derived from foo, then derive bar from foo instead of sc_module. Then, you instantiation will work.

If you want foo to be a submodule of bar, let the derivation as is but fix your initializer lists. You need to forward the name argument to the base class constructor in every class derived from sc_module, i.e. in bar as well. Furthermore, the submodule foo should not have the same name as its parent bar.

// constructor
Bar(sc_core::sc_module_name name)
: sc_module(name) // forward name to base class constructor
, foo("foo")	  // name submodule foo 'foo'
{ ...

Or use the SC_CTOR macro that handles this for you.

 

Greetings

Ralph

Share this post


Link to post
Share on other sites

Side note: You can't use virtual inheritance with SystemC modules.  See the following thread for a related discussion:

Your example doesn't require this, so it should be fine to simply drop the virtual keyword in the sc_module inheritance.

 

Hope that helps,
   Philipp

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now