akaAlso akaAlso - 2 months ago 6
C++ Question

systemc contructor initialization is failing

#ifndef RAM_H
#define RAM_H
#include <systemc.h>


SC_MODULE(ram) {

void ram_proc();

SC_HAS_PROCESS(ram);

private:
sc_clock clock;
};

#endif


then in the ram.cpp I have the following code

#include "ram.h"

ram::ram(sc_module_name name_): clock("clock",1,SC_NS) {std::cout<<"I am in clock "<<std::endl;}

{ //the error is occurring hier

SC_THREAD(ram_proc);

}

void ram::ram_proc () {
std::cout<<"I am in method ram_proc "<<std::endl;
}


The problem is that I am getting this error



expected unqualified-id before ‘{’ token
{


Answer

Fixing for indentation and new lines you code looks like

void ram::ram(sc_module_name name_): clock("clock",1,SC_NS) 
{
    std::cout<<"I am in clock "<<std::endl;
} // <- constructor ends here

{ //the error is occurring hier
    SC_THREAD(ram_proc);
}

As you can see you have two blocks of code. The first block is the constructor body. The second block is not linked to anything. If you want the block containing SC_THREAD(ram_proc); to be in the the constructor then you need

void ram::ram(sc_module_name name_): clock("clock",1,SC_NS) 
{
    std::cout<<"I am in clock "<<std::endl;
    SC_THREAD(ram_proc);
}