简体   繁体   English

自定义构造函数中的 SC_METHOD

[英]SC_METHOD in custom constructor

In my custom constructor i want to use SC_METHOD :在我的自定义构造函数中,我想使用SC_METHOD

class host_command : public sc_module, public bus_if {
public:
//  sc_out<packet_type> out_packet;
    sc_buffer<packet_type> out_packet;

    host_command(char *name, unsigned int limit) : sc_module(name) {
        SC_METHOD(write);
        sensitive << out_packet;
    }

private:
    void write(packet_type data) override {

    }
}

But if i compile it i get following error:但是如果我编译它,我会收到以下错误:

error: ‘SC_CURRENT_USER_MODULE’ has not been declared
         SC_METHOD(write);
         ^

How can i declare SC_CURRENT_USER_MODULE or cannot i use SC_METHOD in custom constructors at all?如何声明SC_CURRENT_USER_MODULE或根本不能在自定义构造函数中使用SC_METHOD

If so, how can i achieve the same functionality?如果是这样,我怎样才能实现相同的功能?

When you declare a module without using the SC_MODULE macro, you must use the SC_HAS_PROCESS macro to indicate the current module for SC_THREADs and SC_METHODs:当您在不使用 SC_MODULE 宏的情况下声明一个模块时,您必须使用 SC_HAS_PROCESS 宏来指示 SC_THREADs 和 SC_METHODs 的当前模块:

SC_HAS_PROCESS(host_command);
host_command(char *name, unsigned int limit) : sc_module(name) {
    SC_METHOD(write);
    sensitive << out_packet;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM