Betrachten Sie den folgenden Code ein:Fehler bei der statischen Methode c Aufruf ++
Automobile.h
class Automobile
{
static string m_stCityCode;
static bool CheckCityCode(const Automobile& obj);
};
Automobile.cpp
bool Automobile::CheckCityCode(const Automobile& obj)
{
return m_stCityCode == obj.m_stCityCode;
}
int main()
{
//do something
}
bekomme ich folgende Fehler
"Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "public: static class
std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > Automobile::m_stCityCode"
([email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@A) myPro C:\Users\zhivko.rusev\Documents\Visual
Studio 2015\Projects\myPro\myPro\Calls.obj 1 "
Ich würde mich über jede Hilfe freuen Dieses Problem lösen. Danke im Voraus!
Sie müssen Ihr statisches Element irgendwo definieren. Es sollte in Ihrem Lieblings C++ Buch erwähnt werden. (Ihr Vergleich ist übrigens immer richtig.) – molbdnilo