使用 Car() 对象声明向量会打印不相关的错误

Declaring a vector with Car() objects prints unrelated error

本文关键字:打印 不相关 错误 向量 声明 Car 对象 使用      更新时间:2023-10-16

我尝试编译以下代码,但出现此错误未定义对"汽车vtable"的引用
并将汽车 ctor 线标记为假
我在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() 中的向量声明

#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() );
}

此错误未定义对"vtable"在此处插入类名"的引用,它实际上是一个链接器而不是编译错误
您有什么虚拟功能没有向我们展示吗?如果
答案是肯定的,请评论它们,如果错误仍然存在,请重新编译并评论。
如果不是,那么它与此向量声明无关