I am a c# developper trying to do c++ things and I cannot understand the issue here:
namespace myNamespace
{
class Application
{
private:
Application(void);
~Application(void);
// Not copyable
Application(const Application&);
Application& operator= (const Application&);
static Application _instance;
[...]
public:
static Application& current(void);
};
}
(this is supposed to be a singleton...)
and this causes the error: "error LNK2001: unresolved external symbol "private: static class myNamespace::Application myNamespace::Application::_instance" (?_instance@Application@myNamespace@@0V12@A)"
Is it because I am using the class I am declaring in the class declaration?
Thanks a lot!
You only declare _instance
in Application class, you need to define it in .cpp file:
namespace myNamespace
{
Application Application::_instance;
}
§ 9.4.2.2
The declaration of a static data member in its class definition is not a definition and may be of an incomplete type other than cv-qualified void. The definition for a static data member shall appear in a namespace scope enclosing the member’s class definition. In the definition at namespace scope, the name of the static data member shall be qualified by its class name using the :: operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With