I’ve been looking into this issue for 2 days, but no luck.
I have the following struct predefined
struct Motor : Port {
Motor(port_t port) : Port(port) {}
void moveAtVelocity(int velocity) { move_at_velocity(m_port, velocity); }
....
};
I’ve then tried to call an instance of the struct
Motor M;
And I’m getting
Error: No matching function for call to Motor::Motor()
Note: Candidates are Motor::Motor(port_t)
How do I call an instance so for example I can use the following method
moveAtVelocity(..);
I know I messed up between classes and structures and constructors and destructors; The thing is that I can’t find a proper tutorial, extra kudos if you can link one for me.
Thanks in advance 🙂
That’s right; what you should have instead is:
(where 123 is a port).
When you just say
Motor M;, the compiler attempts to construct this object by calling a parameterless constructor. You don’t have any defined. You can, however, just pass the required parameter like I’ve shown above.An alternative solution is, of course, to just add a parameterless constructor, but this requires your base class,
Port, to have one too, or for you to pass a fixed value: