I am trying to implement a new feature in an existing QT/c++ project. In this project a header file and a .cpp file were defined. I add two methods (setter and getter) in a .cpp file and it works great. Now, I'm trying to clean up my code and add this methods to the existing .h and .cpp files, but I'm getting a lot of errors and I don't know how to solve it.
In my .h file I have a static method and in this method I want to call a setter method (called in the .cpp file) and then call a getter method in another static method. In the .h file I have the following static variable static std::map<std::string, std::string> data
. Also in the header file I define the getter and setter methods, but when I try to call the setter method (in the .cpp) I get the following error:
qt_gui.lib(Paste.cpp.obj):-1: error: LNK2001: unresolved external symbol "private: static class std::map<class std::basic_string<char,struct std::char_traits<char>,class std ::allocator<char> >,class archx::Component,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std ::allocator<struct std::pair<class std::basic_string<char,struct...
I know that if I want to call methods in a static method, it must also be static. I already declared the map as static and the setter method as static. But I'm still getting these errors. The only way the function works is to declare a the map as a global variable in the .cpp file and also create the getter and setter method (without declaring in the header file), but I think this is not the best practice, because I have a .h file.
Sorry if this is a basic question about c++. But I don't know how to solve it.
Thanks in advance!