I am writing a light program which is based on a car class and a derived class which is a certain make of a car. I need to implement a OO interface for the base and derived classes. Here is what i came up with:
// Definitions.
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
usingnamespace std;
#ifndef __CART_H__
#define __CART_H__
enum Gear{Standard, Automatic};
class Car_t{
public:
Car_t(); // Default CTOR.
Car_t(constint _capacity); // Capacity CTOR.
Car_t(const Car_t& _car); // Copy CTOR.
virtual ~Car_t() = 0; // DTOR.
string GetName() const; // Get the name of the car.
Gear GetGear() const; // Get the type of the car.
int GetProdYear() const; // Get production year function.
int GetCapacity() const; // Get capacity function.
unsignedint GetID() const; // Get ID function.
virtualbool Compare(const Car_t& _car) const; // Comparing between two car objects (same make model or not).
virtualbooloperator<(const Car_t& _car) const; // Is smaller operator.
const Car_t& operator=(const Car_t& _car); // Assignment operator.
private:
constunsignedint m_ID;
int m_capacity;
Gear m_gear;
constint m_prodYear;
string m_name;
staticunsignedint carID; // Car ID static.
protected:
void SetName(const string& _str); // Setting name function.
void SetGear(Gear _gear); // Setting gear function.
void SetCapacity(int _capacity); // Setting gear function.
};
ostream &operator<<(ostream& os, const Car_t& _car);
#endif // #ifndef __CART_H__
#ifndef __FORDT_H__
#define __FORDT_H__
class Ford_t : public Car_t{
public:
Ford_t(); // Default CTOR.
Ford_t(constint _capacity); // Capacity CTOR.
Ford_t(const Ford_t& _ford); // Copy CTOR.
virtual ~Ford_t(); // DTOR.
virtualbooloperator<(const Car_t& _car) const; // Is smaller operator.
};
#endif // #ifndef __FORDT_H__
I need opinions of these interfaces please, also should i reconsider re-arranging the public/private/protected areas? another opinion needed is about the copy CTOR and the = operator, right now the derived class has no = operator as i want it to be copied the same way as the base class (the base clas is abstract), another thing is the virtuality, what do you think of the provided virtual member functions, maybe i need to change them or add something...