|
![](/i/fill.gif) |
Le_Forgeron <jgr### [at] free fr> wrote:
> You can either have all methods of a class static, or use a singleton
> pattern.
If you are using an enforced singleton, and you don't want to expose
*any* implementation detail to the outside, one possibility would be
to do this:
//------------------------------------------------------------
// In the header file:
// ------------------
class TheClass
{
public:
virtual void someFunction() = 0;
virtual int anotherFunction(int parameter) = 0;
virtual void aThirdFunction(double, double) = 0;
};
TheClass& theClassInstance();
//------------------------------------------------------------
//------------------------------------------------------------
// In the implementation file:
// --------------------------
#include "TheClass.hh"
namespace
{
class TheActualClass: public TheClass
{
struct InnerType { int a, b; }
int privateMember;
double anotherPrivateMember;
InnerType aThirdPrivateMember;
void privateFunction();
public:
TheActualClass() { /* constructor */ }
virtual void someFunction()
{
// implement it here
}
virtual int anotherFunction(int parameter)
{
// implement it here
}
virtual void aThirdFunction(double, double)
{
// implement it here
}
};
}
TheClass& theClassInstance()
{
static TheActualClass actualClassInstance;
return actualClassInstance;
}
//------------------------------------------------------------
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |