lundi 24 juillet 2017

Need to understand working of SC_CTOR from systemC

Newbie in CPP as well as systemC In systemC constructor can be defined using SC_CTOR macro `#define SC_MODULE(user_module_name) \ struct user_module_name : ::sc_core::sc_module

define SC_CTOR(user_module_name) \

typedef user_module_name SC_CURRENT_USER_MODULE;                          \
user_module_name( ::sc_core::sc_module_name )

` Need to understand use scope specifier operator before sc_core. As per the macro user can generate constructor but it takes argument sc_module_name. User module "struct user module" is inheriting class sc_module, In class sc_module there are different overloaded constructor like

    sc_module();
sc_module( const sc_module_name& nm ); /* for those used to old style */

/* DEPRECATED */ sc_module( const char* nm );
/* DEPRECATED */ sc_module( const std::string& nm );

As per SC_CTOR it is declaring any object of type sc_moduke_name in constructor body if expanded the constructor will take form user_module(::sc_core::sc_module) { /constructor body/}. To understand simulate same code but failed to create object of type struct B

class mname {
    private:
            char *name;
    public:
            mname() {
                    cout << "mname constructor invoked\n";
                    cout << "\t name\t" << name;
            }

};

class A {
    friend class mname;
    private:
    mname * mn;
    public:
    A() {
            cout << "A constructor called\n";
    }
    A(const mname& m) {
            cout << "freind class constructor of A\n";
    }
    A(const std:: string& s) {
            cout << "string type construfctor\n";
    }

};

struct B: A {
    B(mname ) {
            cout     << "struct b cosntructor called\n";
    }

};

int main() {

    B obj(mname);
    return 0;

}

Aucun commentaire:

Enregistrer un commentaire