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 post
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 post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...