Inder Sidana
Inder Sidana

Reputation: 1

simple C++ basic factory pattern failing

I am new to c++ and am trying a basic factory pattern in C++11 but is failing with error: 'X' does not refer to a value. Any suggestions?

Test Code: X instance = X.createNewInstance();

Original Class

class X
{
public:

    static X createNewInstance() {
        return X();
    };


    void foo() ;

private:

    X(){};

};

Upvotes: 0

Views: 52

Answers (1)

Kolmar
Kolmar

Reputation: 14224

You have to call static member functions with ::

X instance = X::createNewInstance();

Upvotes: 1

Related Questions