链接错误undefined vtable和typeinfo

时间:2014-09-03 09:50:34

标签: c++ c++11 linker-errors virtual-functions

我收到此错误:

Undefined                     first referenced
symbol                              in file
typeinfo for Operand                Expression_Tree.o
vtable for Operand                  Expression.o

通过一些谷歌搜索并查看类似的问题,我发现这可能是因为我如何处理虚拟函数(特别是构造函数/析构函数)

class Expression_Tree
{
 public:
  virtual double           evaluate() = 0;
  virtual std::string      get_postfix() const = 0;
  virtual std::string      get_infix() const = 0;
  virtual std::string      str() const = 0;
  virtual void             print(std::ostream&, int hopCount = 0) const = 0;
  virtual Expression_Tree* clone() const = 0;

  virtual ~Expression_Tree(){}
 protected:
  Expression_Tree() {}
  Expression_Tree(const Expression_Tree& o) = delete; 
  Expression_Tree(Expression_Tree&&) = default;
};

有没有人看到任何与众不同的东西?

1 个答案:

答案 0 :(得分:0)

问题是你们有些人在操作数课上说的,不是它的基础。

class Operand : public Expression_Tree
{
 public:
  Operand& operator=(const Operand&) = default;
  Operand& operator=(Operand&&) = default;
  // void print(std::ostream&, int hopCount = 0) const; <- this was the problem
  std::string get_postfix() const;
  std::string get_infix() const;
  ~Operand() = default;
  Operand(const Operand&) = default;
  Operand(Operand&&) = default;
 protected:
 Operand() 
   : Expression_Tree() {}
};

一旦我删除了void print()一切顺利=)