I'm trying to grasp how to use virtual functions.
Would the following be correct? Also would I not include the virtual in the .cpp file of base?
And when defining the derived class, would I also declare the virtual function in the public of the derived class?
//BASE HEADER FILE
#ifndef BASE_H
#define BASE_H
class Base {
public:
virtual double testFunc() = 0;
int func2();
};
#endif
//BASE.CPP FILE
#include "base.h"
int Base::func2()
{
return 5;
}
//DERIVED HEADER FILE
#ifndef DER_H
#define DER_H
#include "base.h"
class Derived : public Base {
public:
double testFunc();
};
#endif
//DER.CPP FILE
#include "Der.h"
double Derived::testFunc()
{
return 3.2;
}