我想學習C++中類的概念。我編寫了一些代碼來測試我所知道的,編譯代碼時,第一個錯誤是:「沒有匹配函數調用'base :: base()' base base1,base2;」在C++中調用沒有匹配函數
我不知道爲什麼!
這裏是整個代碼:
#include <iostream>
using namespace std;
class base {
int x, y;
public:
base (int, int);
void set_value (int, int);
int area() { return (x*y); }
};
base::base (int a, int b) {
x = a;
y = b;
}
void base::set_value (int xx, int yy) {
x = xx;
y = yy;
}
int main() {
base base1, base2;
base1.set_value (2,3);
base2.set_value (4,5);
cout << "Area of base 1: " << base1.area() << endl;
cout << "Area of base 2: " << base2.area() << endl;
cin.get();
return 0;
}