我在做学校作业。我在wallet.h中有wallet.h和main.cpp.我有一个public:
static std::map<std::string, double> currencies;
和
在main.cpp中,我尝试使用这种货币映射:
std::map<std::string, double> currencies = wallet.currencies;`
我在代码中没有得到任何警告,但是当我尝试编译时,我得到了以下错误:
体系结构X86_64的未定义符号:“Wallet::Currencies”,[...]ld:找不到体系结构x86_64的符号clang:错误:链接器命令失败,退出代码为%1(使用-v查看调用)
null
如果没有一个适当的,最小的,可复制的例子,很难说出任何具体的东西,但似乎
std::map<std::string, double> currencies = wallet.currencies;
定义一个全局非成员变量,而不是
您需要将其显式定义为
std::map<std::string, double> Wallet::currencies = wallet.currencies;
// ^^^^^^^^
// Note scope as Wallet member here
我想,我需要添加
这个问题为我指明了查找问题的方向:C++错误::1:错误:在Qt-Creator中找不到体系结构x86_64的符号