【发布时间】:2012-08-14 18:26:04
【问题描述】:
我已经开始学习 C++,我已经了解 C 和 Java。我开始学习它是因为我想开始使用面向对象编程。
但是,我被代码困住了,因为编译器会生成“对 Actor 的 vtable 的未定义引用”。在这里,您有生成相同错误的代码,而不是原始错误,因为它不太清楚。我真的不知道是什么原因造成的。
struct Actor
{
int x, y;
virtual void move();
};
struct Player : Actor
{
Player(int a, int b)
{
x = a;
y = b;
}
void move();
void draw();
};
void Player::move()
{
++x;
};
main()
{
Actor *act;
act = new Player(10, 20);
}
这个问题可能很愚蠢,我不知道,我已经到处挖了但没有找到可以解决我的问题的东西。
【问题讨论】:
-
这是一个非常糟糕的链接器错误消息。这是什么工具集生成的?
-
这是 GCC。最后一段解释了这个模糊的链接器错误何时出现gcc.gnu.org/faq.html#vtables
标签: c++ class inheritance abstract-class