c++ Abstract Base Classes
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 Code:
#include "Chaser.h" 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. |
Answer (I think)
I found my own answer, the test was easyer than I expected to set up, here are my files:
ABC.h: Code:
#ifndef ABC_H derivedA.h: Code:
#include "ABC.h" Code:
#include "derivedA.h" Code:
#include "ABC.h" Code:
#include "derivedB.h" primeary.cpp: Code:
#include "ABC.h" g++ -c derivedA.cpp g++ -c derivedB.cpp g++ primeary.cpp derivedA.o derivedB.o -o test then I ran test and got this: Code:
exodist@Abydos-64 Tests $ ./test |
All times are GMT -5. The time now is 04:53 PM. |