T
tharringtonan
I am compiling the following code, main.cpp, as follows:
gcc main.cpp
I get the following compile error:
main.cpp: In function `int main()':
main.cpp:28: no matching function for call to `CPolygon::area()'
The code is listed below:
#include <iostream>
using namespace std;
class CPolygon {
public:
virtual void set_values (int a, int b) { width=a; height=b; };
protected:
int width, height;
};
class CRectangle: public CPolygon {
public:
int area () { return (width * height); };
};
int main ()
{
CPolygon * ppoly1 = new CRectangle;
ppoly1->set_values (4,5);
cout << ppoly1->area() << endl;
return 0;
}
Why does this not compile?
gcc main.cpp
I get the following compile error:
main.cpp: In function `int main()':
main.cpp:28: no matching function for call to `CPolygon::area()'
The code is listed below:
#include <iostream>
using namespace std;
class CPolygon {
public:
virtual void set_values (int a, int b) { width=a; height=b; };
protected:
int width, height;
};
class CRectangle: public CPolygon {
public:
int area () { return (width * height); };
};
int main ()
{
CPolygon * ppoly1 = new CRectangle;
ppoly1->set_values (4,5);
cout << ppoly1->area() << endl;
return 0;
}
Why does this not compile?