I am very familiar with java, and in java use Interface classes often. Now I am re-learning c++ after a while of not using it, and never having used it for anything majior before.
I am trying to use the c++ equivilent of interfaces, or in other words abstract defenitions to which multiple derived classes need to conform with no actual implementation of the base class.
like most tutorials have you define the 'Vehicle' main class, then 'car', 'bus' and 'train' derived classes.
Most tutorials I have found show you the implementation in clips of code:
http://www.cplusplus.com/doc/tutorial/tut4-4.html
http://software.allindiansite.com/cfaq/abcs.html
but they do nto explain a few things:
Once you define the header file, do you need a .cpp, do you need to compile anything specifically for the interface?
or do you simply include the header in the derived class?
example:
here is a header, chaser.h:
Code:
#ifndef CHASER_H
#define CHASER_H
#include "MapObject.h"
/*
Interface for anything that needs to track on object on the map
*/
namespace OpenRPGGDE
{
class MapObject;
class Chaser
{
public:
virtual void endChase(MapObject&) = 0;
};
}
#endif //CHASER_H
do I need a chaser.cpp file liek this:
Code:
#include "Chaser.h"
#include "MapObject.h"
using namespace std;
using namespace OpenRPGGDE;
namespace OpenRPGGDE
{
void Chaser::endChase(MapObject& theObject)
{}
}
or is that completely unneccessary, it compiles fine with g++ -c chaser.cpp -o chaser.o
It seems to me that making a .o file for all the interfaces would not be necessary, but my code is not yet to the point where I can test this yet. As well I would rather not write my code making any assumptions over this. I am going to try and implement a test for this, but I would liek some information to alleviate the headackes I am sure to have over this.
Any help is much appreciated.