Below code instantiates a derived singleton object based on environment variable. The compiler errors saying error C2512: 'Dotted' : no appropriate default constructor. I don't understand what the compiler is complaining about.
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
class Dotted;
class Singleton{
public:
static Singleton instant(){
if (!instance_)
{
char * style = getenv("STYLE");
if (!style){
if (strcmp(style,"dotted")==0)
{
instance_ = new Dotted();
return *instance_;
}
}
else{
instance_ = new Singleton();
return *instance_;
}
}
return *instance_;
}
void print(){cout<<"Singleton";}
~Singleton(){};
protected:
Singleton(){};
private:
static Singleton * instance_;
Singleton(const Singleton & );
void operator=(const Singleton & );
};
class Dotted:public Singleton{
public:
void print(){cout<<"Dotted";}
protected:
Dotted();
};
Dotted::Dotted():Singleton(){}
int main(){
Singleton::instant().print();
cin.get();
}