For a university project we have to create several classes, all depending on the abstract class function.
But while trying to define the class Compose
, which has to combine two different functions passed as constructor arguments, I get several problems as shown below.
How exactly can I use my abstract class as a data type without problems in this case?
Abstract Class Function
:
class Function{
protected:
double _a, _b, _c, _m;
public:
Function(double a, double b, double c, double m): _a(a), _b(b), _c(c), _m(m){}
virtual double evaluate(double x) =0;
void print(){ for(double i=0.0; i==1.0; i+=0.1) cout << "Wert: " << i << ", Ergebnis: " << evaluate(i) << endl;}
};
Class Compose
:
class Compose:public Function{
private:
Function *_f1, *_f2;
public:
Compose(Function & f1, Function & f2):Function(0,0,0,0), _f1(f1), _f2(f2){}
double evaluate(double x){}
};
Error Messages:
21:54:02 **** Incremental Build of configuration Debug for project Aufgabe_10_1 ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -o "src\\Aufgabe_10_1.o" "..\\src\\Aufgabe_10_1.cpp"
..\src\Aufgabe_10_1.cpp: In constructor 'Compose::Compose(Function&, Function&)':
..\src\Aufgabe_10_1.cpp:37:7: error: cannot convert 'Function' to 'Function*' in assignment
_f1 = f1;
^
..\src\Aufgabe_10_1.cpp:38:7: error: cannot convert 'Function' to 'Function*' in assignment
_f2 = f2;
^
..\src\Aufgabe_10_1.cpp: In member function 'virtual double Compose::evaluate(double)':
..\src\Aufgabe_10_1.cpp:40:28: warning: no return statement in function returning non-void [-Wreturn-type]
double evaluate(double x){}
^
21:54:03 Build Finished (took 423ms)