EDIT:
Thanks for the help guys! i've just got one more question, how would i use the constructor for the Obj? i want to declare its (x,y) position but i dont know how to do so, i included what i tried in my new updated code.
ERROR:
F:\C++\AbstractBaseClass_Shapes\main.cpp||In function 'int main()':|
F:\C++\AbstractBaseClass_Shapes\main.cpp|7|error: initializer expression list treated as compound expression|
F:\C++\AbstractBaseClass_Shapes\main.cpp|7|warning: left-hand operand of comma has no effect|
F:\C++\AbstractBaseClass_Shapes\main.cpp|7|error: invalid conversion from 'int' to 'Abc*'|
||=== Build finished: 2 errors, 1 warnings ===|
main.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
#include "Abc.h"
usingnamespace std;
int main()
{
Abc * Obj;
//Abc * Obj(4,3); doesnt work, how to do this?
Obj = new Circle(5); //allocate new circle object
std::cout << "The area of the circle: " << Obj->Area() << std::endl;
delete Obj;
}
Obj is a pointer so you have to write Obj->Area() to call the Area function.
In Ellipse and Circle you have declared Area functions with extra parameters. I guess this is just a mistake because when you define them you have left out the parameters.
Peter87 nailed both errors. You need to change Obj.Area() to Obj->Area() (in main), and you need to declare and define Area() without parameters in both Ellipse and Circle. In other words, you haven't overridden (abstract) ABC::Area() yet, you've declared and defined two new methods, Ellipse::Area(double, double) and Circle::Area(double). This makes Ellipse and Circle abstract classes still.
Thanks for the help guys! i've just got one more question, how would i use the constructor for the Obj? i want to declare its (x,y) position but i dont know how to do so, i included what i tried in my new updated code.