A C++ Virtual Function Problem

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 Shootwhat should i do?

Did you try Stackoverflow? I saw some similar compilation error 2-3 days back there but couldn’t recall it.

Maybe give it a chance in the recent threads

My English is poor.I don’t know how to describe this problem.
There is no way to search on stack overflow.
Actually, it’s easy to solve, but the students asked this question. I don’t know how to answer it.

Edit: not a complete answer, but may help you on the right track with respect to the jargon used

2 Likes