Есть два класса
class cFunction
{
public:
cFunction(double _a, double _b, double _c, double _x);
virtual double getY();
protected:
virtual double function();
cArguments *args;
double x, y;
};
class cFunction1 : public cFunction
{
public:
cFunction1(double _a, double _b, double _c, double _x);
protected:
double function();
};
конструктор для родителя выглядит как
cFunction::cFunction(double _a, double _b, double _c, double _x)
{
args = new cArguments(_a,_b,_c);
x = _x;
y = function();
}
если для наследника конструктор сделать как написано ниже, то метод function() вызывается родительский, несмотря на то, что он виртуальный
cFunction1::cFunction1(double _a, double _b, double _c, double _x) :
cFunction(_a, _b, _c, _x)
{
}
если делать так
cFunction1::cFunction1(double _a, double _b, double _c, double _x)
{
args = new cArguments(_a,_b,_c);
x = _x;
y = function();
}
то выходит ошибка
In constructor 'cFunction1::cFunction1(double, double, double, double)':
no matching function for call to 'cFunction::cFunction()'
как сделать, что бы конструктор наследника использовал собственный метод function?