error: cannot call member function 'singleton* singleton::create(char)' without object
s1 = singleton::create(x);
^
test.cpp:27:29: error: cannot call member function 'singleton* singleton::create(char)' without object
s2 = singleton::create(y);
^
#include <iostream>
using namespace std;
class singleton
{
char c;
static singleton *object;
singleton(char x) : c(x) {}
public:
singleton *create(char x)
{
if (!object)
object = new singleton(x);
return object;
}
void show();
};
singleton *singleton ::object = 0;
void singleton::show()
{
cout << c;
}
int main()
{
char x, y;
singleton *s1, *s2;
cin >> x >> y;
s1 = singleton::create(x);
s2 = singleton::create(y);
s1->show();
s2->show();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire