Jump to content

Constructor issue


aarone

Recommended Posts

Hi guys! 

I'm new to SystemC and still trying to figure out basic stuff.

 

In preparation to pass some arguments to a constructor, I'm looking how to replace the SC_CTOR macro. In the code below, the "SC_CTOR(my_module);" line works well but when I comment it out and replace by direct constructor declaration "my_module(sc_module_name nm);" it doesn't compile.

 

I'll appreciate any hint.

 

Thanks,

Aaron

 

---------------------------------------------

 

// main.cpp
#include <systemc>
#include "my_module.h"
 
using namespace sc_core;
 
int sc_main(int argc, char* argv[])
{
   my_module my_module_i("my_module_i");
   sc_start();
   return 0;
}
 
// my_module.h
#ifndef MY_MODULE_H
#define MY_MODULE_H
#include <systemc>
 
SC_MODULE(my_module)
{
   // this constructor works
   SC_CTOR(my_module);
 
   // this constructor doesn't work
   //my_module(sc_module_name nm);
 
};//endclass 
#endif
 
// my_module.cpp
#include <iostream>
using std::cout;
using std::endl;
 
#include <systemc>
#include "my_module.h"
 
using namespace sc_core;
 
SC_HAS_PROCESS(my_module);
my_module::my_module(sc_module_name nm)
   : sc_module(nm)
{
 
   cout << "Hello world" << endl;
 
}
 
Link to comment
Share on other sites

Hi it works for me ,

here is the code

// main.cpp
#include <systemc>
#include "my_module.h"
 
using namespace sc_core;
 
int sc_main(int argc, char* argv[])
{
   my_module my_module_i("my_module_i");
   sc_start();
   return 0;
}
// my_module.h
#include <systemc>
 
using namespace sc_core;
 

 
// my_module.h
#ifndef MY_MODULE_H
#define MY_MODULE_H
#include <systemc>
 
SC_MODULE(my_module)
{
   // this constructor works
   //SC_CTOR(my_module);
 
   // this constructor doesn't work
   my_module(sc_module_name nm);
 
};//endclass
#endif

&

// my_module.cpp
#include <iostream>
using std::cout;
using std::endl;
 
#include <systemc>
#include "my_module.h"
 
using namespace sc_core;
 
SC_HAS_PROCESS(my_module);
my_module::my_module(sc_module_name nm)
   : sc_module(nm)
{
 
   cout << "Hello world" << endl;
 
}

I used  g++ costr.cpp my_module.cpp -lsystemc to compile. Can you check this if it works? else can you post your compiler errors?

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.

Guest
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...