jeudi 4 avril 2019

Undefined symbols for architecture x86_64 C++11

I’m trying to setup a simple static variable in C++ and am running into an issue of

Undefined symbols for architecture x86_64: “MyNamespace::MyClass::myVariable_”, referenced from: MyNamespace:: MyClass::MyFunction(MyNamespace::Type)

My header looks like:

namespace MyNamespace {

    class MyClass {
    public:
        static void SetMyVariable(const Type var);

    private:
        static Type myVariable_;

    };
}

Then my implementation looks like:

namespace MyNamespace {

    void MyClass::MyFunction(const Type var) {
        myVariable_ = var;
    }
}

There is something I’m not understanding about how to access the variable. How can I fix this?

Aucun commentaire:

Enregistrer un commentaire