提问者:小点点

如何修复体系结构x86_64:C++编译器错误的未定义符号?


我在做学校作业。我在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


共2个答案

匿名用户

如果没有一个适当的,最小的,可复制的例子,很难说出任何具体的东西,但似乎

std::map<std::string, double> currencies = wallet.currencies;

定义一个全局非成员变量,而不是成员。

您需要将其显式定义为类的成员:

std::map<std::string, double> Wallet::currencies = wallet.currencies;
//                            ^^^^^^^^
//    Note scope as Wallet member here

匿名用户

我想,我需要添加;wallet::currences=USD“,10000/code>设置为wallet.cpp以获得默认值。钱包是空的。

这个问题为我指明了查找问题的方向:C++错误::1:错误:在Qt-Creator中找不到体系结构x86_64的符号

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(修复|体系结构|x86_64|c++|编译器|未定义|符号)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?