Re: Help with solving seemingly mutually exclusive problems please
On Oct 19, 5:02 pm, red floyd <no.s...@here.dude> wrote:
Zilla wrote:
I put everything in one file for ease of use; also I have #include
<*.h> files instead of the <*> since my compiler is pre-ANSI C so it
needs the .h
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
class Cmd {
public:
virtual ~Cmd() {}
char* printCmd()
{
return _name;
}
protected:
Cmd() {}
char _name[16];
};
class ACmd : public Cmd {
public:
static Cmd* getInstance()
{
if (!_instance) {
_instance=new ACmd;
}
return _instance;
}
~ACmd() {}
private:
ACmd()
{
strcpy(_name, "ACmd");
}
static Cmd* _instance;
};
class BCmd : public Cmd {
public:
static Cmd* getInstance()
{
if (!_instance) {
_instance=new BCmd;
}
return _instance;
}
~BCmd() {}
private:
BCmd()
{
strcpy(_name, "ACmd");
I suspect your error lies here.
}
static Cmd* _instance;
};
typedef struct {
Cmd* cmd;
} CmdS;- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
How? ACmd and BCmd are singletons, and that's how one codes one. See
Design Patterns book.