jeudi 18 février 2021

Basic Class Inheritance in C++

I am typing the following code and I am getting the following error at line-1
[Error] no matching function for call to 'int_adder::add()

#include <iostream> 
using namespace std; 

class adder{ 
  public: 
  void add(){ cout <<"adder::add() "; } 
}; 

class int_adder : public adder{ 
  public: 
  int add(int a, int b){
    return (a + b); 
  }
};

int main(){ 
  int_adder ia; 
  ia.add(); //LINE-1 
  cout << ia.add(10, 20); //LINE-2 
  return 0; 
}

Aucun commentaire:

Enregistrer un commentaire