RPN 式の電卓を作成していますが、解決できないように見えるリンカー エラーが発生します。正しい操作と値を選択するために、二重ディスパッチを使用しようとしています。クラス階層の最上位から開始し、オペランドに到達するまで下に移動します。演算子から派生したものではありません。
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
これらの関数の定義は、基本クラスから始まります。
class Operation : public Token {
public:
using pointer_type = TOKEN_PTR_TYPE(Operation);
virtual unsigned number_of_args() const = 0;
virtual Operand::pointer_type perform( TokenList& params );
};
次の派生クラスは Operator で、次に Operator ヘッダーの Addition です。
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);
};
最後に、整数ソース ファイルで関数を定義します。
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);
}
私は C++ リンカとリンカ エラーに関する多くの資料を読んできましたが、これを理解することはできません。私がやっているばかげたことに対して、私はいつもリンカエラーを受け取ります。誰でも問題を見つけることができますか?
ありがとう