SiGa Posted November 6, 2019 Report Share Posted November 6, 2019 I have a class with an sc_event which should be readable and writeable through getter and setter methods. class IntWithEvent { private: sc_event _ev_wr; sc_event _ev_trigger; public: const sc_event& get_write_event() const { return _ev_wr; } const sc_event& get_trigger_event() const { return _ev_trigger; } void set_trigger_event(sc_event &ev) const { _ev_trigger = ev; // E0349 no operator "=" matches these operands } } Writing the getters was no problem. However the setter throws me an error of no matching assignment operator. Do I need to store a pointer to a sc_event and then set the pointer to the address of the parameter? It doesn't give me compile errors like this. class IntWithEvent { private: sc_event _ev_wr; sc_event *_ev_trigger; public: const sc_event& get_write_event() const { return _ev_wr; } const sc_event& get_trigger_event() const { return *_ev_trigger; } void set_trigger_event(sc_event *ev) { _ev_trigger = ev; } } I was taught to avoid pointers where I can. Is there a way to avoid the pointers? Quote Link to comment Share on other sites More sharing options...
Roman Popov Posted November 7, 2019 Report Share Posted November 7, 2019 Looks like XY problem to me. If you need pointer to event, use pointer. SiGa 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.