C++ 我怎样才能找到这个不可思议的链接器错误的原因?
我正在为RPN表达式开发一个计算器,我遇到了一个链接器错误,我似乎无法解决。为了选择正确的操作和值,我尝试使用双重分派。我将从类层次结构的顶部开始,向下移动,直到达到操作数为止。它不是从运算符派生的C++ 我怎样才能找到这个不可思议的链接器错误的原因?,c++,visual-studio,linker,linker-errors,lnk2001,C++,Visual Studio,Linker,Linker Errors,Lnk2001,我正在为RPN表达式开发一个计算器,我遇到了一个链接器错误,我似乎无法解决。为了选择正确的操作和值,我尝试使用双重分派。我将从类层次结构的顶部开始,向下移动,直到达到操作数为止。它不是从运算符派生的 integer.obj : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class Operand> __thiscall Operand::perform_additi
integer.obj : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class Operand> __thiscall Operand::perform_addition(class std::vector<class std::shared_ptr<class Token>,class std::allocator<class std::shared_ptr<class Token> > > &)" (?perform_addition@Operand@@UAE?AV?$shared_ptr@VOperand@@@std@@AAV?$vector@V?$shared_ptr@VToken@@@std@@V?$allocator@V?$shared_ptr@VToken@@@std@@@2@@3@@Z)
tokenizer.obj : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class Operand> __thiscall Operand::perform_addition(class std::vector<class std::shared_ptr<class Token>,class std::allocator<class std::shared_ptr<class Token> > > &)" (?perform_addition@Operand@@UAE?AV?$shared_ptr@VOperand@@@std@@AAV?$vector@V?$shared_ptr@VToken@@@std@@V?$allocator@V?$shared_ptr@VToken@@@std@@@2@@3@@Z)
ut_rpn_evaluator.obj : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class Operand> __thiscall Operand::perform_addition(class std::vector<class std::shared_ptr<class Token>,class std::allocator<class std::shared_ptr<class Token> > > &)" (?perform_addition@Operand@@UAE?AV?$shared_ptr@VOperand@@@std@@AAV?$vector@V?$shared_ptr@VToken@@@std@@V?$allocator@V?$shared_ptr@VToken@@@std@@@2@@3@@Z)
tokenizer.obj : error LNK2001: unresolved external symbol "public: virtual class std::shared_ptr<class Operand> __thiscall Operation::perform(class std::vector<class std::shared_ptr<class Token>,class std::allocator<class std::shared_ptr<class Token> > > &)" (?perform@Operation@@UAE?AV?$shared_ptr@VOperand@@@std@@AAV?$vector@V?$shared_ptr@VToken@@@std@@V?$allocator@V?$shared_ptr@VToken@@@std@@@2@@3@@Z)
C:\Users\User\OneDrive\School\Semester 3\Course\project\Debug\ut_rpn_evaluator.exe : fatal error LNK1120: 2 unresolved externals
下一个派生类是Operator,然后添加到Operator头中:
class Addition : public LAssocOperator {
DEF_IS_CONVERTABLE_FROM(Addition)
DEF_PRECEDENCE(ADDITIVE)
public:
Operand::pointer_type perform(TokenList& params);
};
这是我在操作员源代码文件中的实现:
Operand::pointer_type Addition::perform(TokenList& param){
Operand::pointer_type op;
op = op->perform_addition(params);
return op;
}
这是操作数头文件中函数的声明:
class Operand : public Token
{
public:
using pointer_type = TOKEN_PTR_TYPE(Operand);
//Operation Definitions
virtual Operand::pointer_type perform_addition(TokenList& params);
};
整数派生自操作数,这是标头中类定义的一部分:
class Integer : public Operand {
public:
//usings for pointer and value
private:
//member for value
public:
//Constructor
value_type get_value() const { return value_; }
Operand::pointer_type perform_addition(TokenList& params);
};
最后,我在integer源文件中定义了函数:
Operand::pointer_type Integer::perform_addition(TokenList& params){
Integer::value_type value = Integer::value_type(0);
for (auto val : params){
value += convert<Integer>(val)->get_value();
}
return make_operand<Integer>(value);
}
操作数::指针类型整数::执行加法(令牌列表和参数){
整型::值\类型值=整型::值\类型(0);
用于(自动值:参数){
value+=convert(val)->get_value();
}
返回make_操作数(值);
}
我一直在阅读C++链接器和链接器错误的很多资料,但我无法理解这一点。我总是因为我做的蠢事而得到链接器错误。有人能发现问题吗
谢谢
此方法尚未在任何地方实现。如果您希望它是纯虚拟的,那么您需要在末尾添加
=0
。谢谢,这似乎可以解决问题。
Operand::pointer_type Integer::perform_addition(TokenList& params){
Integer::value_type value = Integer::value_type(0);
for (auto val : params){
value += convert<Integer>(val)->get_value();
}
return make_operand<Integer>(value);
}
class Operand : public Token
{
// ....
virtual Operand::pointer_type perform_addition(TokenList& params);