class Generic : public Obj
{
public:
Generic() { }
virtual void set(const int pwm)
{
std::cout<< i am generic<<std::endl;
}
this is base .
class Shoot : public Generic
{
public:
Shoot() {}
virtual void set(const int left, const int right)
{
std::cout << "I am shoot set!" << left << " " << right << std::endl;
}
};
this is son.
class SingleShoot : public Shoot
{
public:
SingleShoot () {}
virtual void set(const int pwm) override
{
std::cout << "I am SngerShoot set!" << pwm << std::endl;
}
};
this is grandson.
void opcontrol()
{
std::shared_ptr<Generic> shoot =std::make_shared<SingleShoot>();
shoot->set(127); // it's error,
}
Compiler Error Tips:
too few arguments to function call, expected 2, have 1; did you mean ‘Generic::set’?
‘Generic::set’ declared here
The simplest approach:
add virtual void set(int ){;}
to class shoot
if i don’t add virtual void set(int pwm) =0
or virtual void set(int pwm) {;}
in class Shoot
what should i do?