class MyMathFuncs
{
public:
// Returns a + b
virtualdouble Add(double a, double b)=0;
// Returns a - b
virtualdouble Subtract(double a, double b)=0;
// Returns a * b
virtualdouble Multiply(double a, double b)=0;
// Returns a / b
// Throws DivideByZeroException if b is 0
virtualdouble Divide(double a, double b)=0;
};
Would I have to write the key word virtual when I define it threw inheritance?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class MyMathFuncs:public MyMathFuncs
{
public:
// Returns a + b
static __declspec(dllexport) double Add(double a, double b);
// Returns a - b
static __declspec(dllexport) double Subtract(double a, double b);
// Returns a * b
static __declspec(dllexport) double Multiply(double a, double b);
// Returns a / b
// Throws DivideByZeroException if b is 0
static __declspec(dllexport) double Divide(double a, double b);
};
Just wondering why you need to have them as pure virtual functions, this means you have to redefine them for every derived class. If you don't, then you won't be able to create an object for that class because it is "incomplete". You may well have a valid reason for doing this, I am just wondering.
virtual functions cannot be static. A virtual function needs an instance of an object so it can know which version to call. static functions by definition have no instance. Therefore the two concepts are mutually exclusive.