【发布时间】:2018-05-14 03:44:20
【问题描述】:
考虑以下代码:
Automobile.h
class Automobile
{
static string m_stCityCode;
static bool CheckCityCode(const Automobile& obj);
};
汽车.cpp
bool Automobile::CheckCityCode(const Automobile& obj)
{
return m_stCityCode == obj.m_stCityCode;
}
int main()
{
//do something
}
我收到以下错误
"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"
(?m_stCityCode@Automobile@@2V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) myPro C:\Users\zhivko.rusev\Documents\Visual
Studio 2015\Projects\myPro\myPro\Calls.obj 1 "
对于解决此问题的所有帮助,我将不胜感激。提前致谢!
【问题讨论】:
-
你需要在某处定义你的静态成员。它应该在您最喜欢的 C++ 书籍中提及。 (顺便说一句,你的比较总是正确的。)
标签: function methods static boolean