Constructors

Jan 1, 2020 at 3:15am
What is wrong with this constructor??


class Event
{
public:

Event(Message cm, BaseEntity bfsm) : current_message(cm), fsm(bfsm) { return;}
~Event() { }


Event(const Event &e)
{
e.current_message = current_message;
e.fsm = fsm;
}



DeliveryEnum task_responsibility;

void *pTaskPayload; //any payload that goes along with the responsibility

Event wrap_message(Message &m, BaseEntity &e); ///takes a message and wraps it into an event.

void executeFSM(Entity e, Message m); //called when task is up for usage. Uses inheritance.
//dispatch() function called on the inherited class calls the
//the FSM specific to that Entity

private:
Message &current_message;
BaseEntity &fsm; //finite state machine
};

#endif /* Event_hpp */


THe compiler says: Constructor for event must expiclity initialize the reference member "current message"
Jan 1, 2020 at 5:01am
Look at what you are attempting to assign to (left side) and from (right side) of your copy constructor.
Jan 1, 2020 at 11:40am
The main problem is that current_message and fsm are references.

The first constructor tries to assign temporary variables to these references and thus creates dangling references.

The second constructor doesn't make sense at all.
Topic archived. No new replies allowed.