I am working on a simple C ++ program and it is difficult for me to understand the compiler error I received. The problem was caused by the fact that I was trying to create a derived class from a base class. I posted my code below with the same structure, but changed the names.
Baseclass.h
#ifndef BASECLASS_H
#define BASECLASS_H
class BaseClass {
public:
BaseClass(void);
virtual int method1(void) = 0;
virtual int method2(void) = 0;
virtual float method3(void) = 0;
};
#endif
DerivedClass.h
#ifndef DERIVEDCLASS_H
#define DERIVEDCLASS_H
#include "DerivedClass.h"
class DerivedClass: public BaseClass
{
public:
DerivedClass(void);
};
#endif
DerivedClass.cpp
#include "DerivedClass.h"
DerivedClass::DerivedClass(void)
{
}
int DerivedClass::method1(void)
{
}
int DerivedClass::method2(void)
{
}
float DerivedClass::method3(void)
{
}
When I try to compile this, I get the following error for all virtual methods:
no 'int DerivedClass::methodX()' member function declared in class 'DerivedClass'
As soon as I declare these methods in "DerivedClass.h", the errors go away as the compiler now knows about the methods.
. DerivedClass.h? #include DerivedClass.h, BaseClass.h, , DerivedClass.cpp . - ?