gpt4 book ai didi

c++ - 使用 Car() 对象声明 vector 会打印不相关的错误

转载 作者:行者123 更新时间:2023-11-28 06:34:37 26 4
gpt4 key购买 nike

我尝试编译以下代码,但出现此错误 undefined reference to 'vtable for Car'
并将 Car ctor 行标记为 false
我在 main() 中包含了“Car.h”和“Road.h”(Road.h 已经包含了 Car.h,但是 Car.h 没有)

class Car
{

protected:
std::string name;
public:
Car(std::string name="Ship")
{
std::ostringstream tmp;
std::string temp;
tmp << name << ++id;
name = tmp.str();
}
static int id = 0;
virtual void func(); //redefined in the subclasses Turbo and Tank
virtual void mov(); //redefined in the subclasses Turbo and Tank
};

main() 中的 vector 声明

#include <iostream>
#include <vector>
#include <string>
#include "Car.h"
#include "Road.h"
using std::cout;
using std::endl;
using std::vector;
int main()
{
vector<Car>
Shipyard( 10, Car() );

}

最佳答案

这个错误undefined reference to 'vtable for "insert ClassName here"'它实际上是链接器而不是编译错误
您是否有任何未向我们展示的虚函数?
如果答案是肯定的,请评论它们,如果错误仍然存​​在,请重新编译并评论。
如果不是那么它与这个vector声明无关

关于c++ - 使用 Car() 对象声明 vector 会打印不相关的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26948828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com