S
Steven T. Hatton
I will assume many people reading this would never create anything similar
to the example below. So let me preface this with _*IF*_ you were in a
situation where you had to chose between using #includes or forward
declaring each class in diamond.h, which would you choose? Why?
If there is something fundamentally wrong with the way I've approached the
structure of this example, I am interested to know. As for preferences and
tastes, I would really like to stay focused on the question above.
//north.cpp
#include "north.h"
namespace diamond {
North::North(){}
North::~North(){}
};
//east.cpp
#include "east.h"
namespace diamond {
East::East() : North(){}
East::~East(){}
};
//west.cpp
#include "west.h"
namespace diamond {
West::West() : North(){}
West::~West(){}
};
//south.cpp
#include "south.h"
namespace diamond {
South::South(): East(), West(){}
South::~South(){}
};
//diamond.cpp
#include "diamond.h"
namespace diamond {
Diamond:iamond(){}
Diamond::~Diamond(){}
};
//north.h
#ifndef DIAMONDNORTH_H
#define DIAMONDNORTH_H
namespace diamond {
class North{
public:
North();
~North();
};
};
#endif
//east.h
#ifndef DIAMONDEAST_H
#define DIAMONDEAST_H
#include "north.h"
namespace diamond {
class East : virtual public North
{
public:
East();
~East();
};
};
#endif
//west.h
#ifndef DIAMONDWEST_H
#define DIAMONDWEST_H
#include "north.h"
namespace diamond {
class West : virtual public North
{
public:
West();
~West();
};
};
#endif
//south.h
#ifndef DIAMONDSOUTH_H
#define DIAMONDSOUTH_H
#include "east.h"
#include "west.h"
namespace diamond {
class South : virtual public East, virtual public West
{
public:
South();
~South();
};
};
#endif
//diamond.h
#ifndef DIAMONDDIAMOND_H
#define DIAMONDDIAMOND_H
namespace diamond
{
class Diamond
{
public:
Diamond();
~Diamond();
private:
East e;
North n;
West w;
South s;
};
};
to the example below. So let me preface this with _*IF*_ you were in a
situation where you had to chose between using #includes or forward
declaring each class in diamond.h, which would you choose? Why?
If there is something fundamentally wrong with the way I've approached the
structure of this example, I am interested to know. As for preferences and
tastes, I would really like to stay focused on the question above.
//north.cpp
#include "north.h"
namespace diamond {
North::North(){}
North::~North(){}
};
//east.cpp
#include "east.h"
namespace diamond {
East::East() : North(){}
East::~East(){}
};
//west.cpp
#include "west.h"
namespace diamond {
West::West() : North(){}
West::~West(){}
};
//south.cpp
#include "south.h"
namespace diamond {
South::South(): East(), West(){}
South::~South(){}
};
//diamond.cpp
#include "diamond.h"
namespace diamond {
Diamond:iamond(){}
Diamond::~Diamond(){}
};
//north.h
#ifndef DIAMONDNORTH_H
#define DIAMONDNORTH_H
namespace diamond {
class North{
public:
North();
~North();
};
};
#endif
//east.h
#ifndef DIAMONDEAST_H
#define DIAMONDEAST_H
#include "north.h"
namespace diamond {
class East : virtual public North
{
public:
East();
~East();
};
};
#endif
//west.h
#ifndef DIAMONDWEST_H
#define DIAMONDWEST_H
#include "north.h"
namespace diamond {
class West : virtual public North
{
public:
West();
~West();
};
};
#endif
//south.h
#ifndef DIAMONDSOUTH_H
#define DIAMONDSOUTH_H
#include "east.h"
#include "west.h"
namespace diamond {
class South : virtual public East, virtual public West
{
public:
South();
~South();
};
};
#endif
//diamond.h
#ifndef DIAMONDDIAMOND_H
#define DIAMONDDIAMOND_H
namespace diamond
{
class Diamond
{
public:
Diamond();
~Diamond();
private:
East e;
North n;
West w;
South s;
};
};