使用 Car() 对象声明向量会打印不相关的错误
Declaring a vector with Car() objects prints unrelated error
我尝试编译以下代码,但出现此错误未定义对"汽车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"在此处插入类名"的引用,它实际上是一个链接器而不是编译错误
您有什么虚拟功能没有向我们展示吗?如果
答案是肯定的,请评论它们,如果错误仍然存在,请重新编译并评论。
如果不是,那么它与此向量声明无关
相关文章:
- 如果条件不相关,我应该更喜欢两个 if 语句而不是 if-else 语句吗?
- 虚假唤醒是否会解锁所有等待线程,甚至是不相关的线程?
- 如何打印不带空格的输入整数?
- std::less是否应该允许在编译时比较不相关的指针?
- 0 的 2D 数组 不相关循环的破坏逻辑 - C++
- 为什么数组到指针的输出不相关
- 如何使用模板元编程在自由函数C++链接两个不相关的类
- cout 打印不准确的结果,printf 打印准确的结果
- 为什么在使用不相关的宏时会阻止 while 循环结束?
- 将积分类型的数组作为另一个不相关的积分类型的阵列进行访问的安全且符合标准的方法
- 强制转换为不相关的引用类型是否违反严格的别名规则?
- 在 Windows 上打印不起作用
- 为什么我的代码在添加不相关的代码行后工作方式不同?
- 尝试编写函数尝试从字符串中提取数字,但它返回不相关的数字
- VSCODE C++ IntelliSense为替代定义找到不相关的Yocto Sysroots
- 什么保证两个不相关的线程中的不同不相关对象没有(不可避免的)争用条件?
- 对类型 'A *' 的非常量左值引用不能绑定到不相关的类型 'std::shared_ptr<A>' 的值
- 将函数从控制台应用程序移动到共享库项目似乎会带来不相关的编译错误
- 使用 Car() 对象声明向量会打印不相关的错误
- 标准流打印不相关字符