模板参数需要正向声明,或者类型定义需要已知
Do template parameters need to be forward declared or does the type definition to be known
基本上我有这个代码,但GCC抱怨矢量不能用空类型构造。有人遇到这个问题吗之前我应该提到的是,Vertex3D仅通过文件,因此不应该有理由将整个类型编译器已知。我不知道模板在这方面的表现尊敬
//#include "cgVertex3D.hpp"
#include "cgDirection3D.hpp"
#include "cgHandedness.hpp"
class Vertex3D; // Forward declaration to avoid mutual header include
class Polygon3D {
// Vertices constituting this polygon
vector<Vertex3D*> *vertices = NULL;
public:
...
所有标准容器都要求类型完整。由于您正在创建一个指针向量,所以这不是问题(从不完整类型派生的指针类型可以用作类型参数)。代码中的错误是= NULL;
部分(好吧,除非std::vector
本身不可用,否则您还必须包含<vector>
),这无论如何都没有什么意义。您在构造函数中初始化数据成员,而不是在类定义体中初始化。而且你绝对不需要有一个指向向量的指针。
// note that you probably *shouldn't* use pointers here, but whatever
class Polygon3D {
std::vector<Vertex3D*> vertices;
Polygon3D();
// ...
};
// ...
Polygon3D::Polygon3D() : vertices() {}
相关文章:
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- C2678 二进制 '==':未找到采用 'Card' 类型左操作数的运算符(或者没有可接受的转换)
- 二进制 '==':未找到采用 'Enemy' 类型左侧操作数的运算符(或者没有可接受的转换)
- 为什么C++数组索引值是有符号的,而不是围绕size_t类型构建的(或者我错了)
- 错误 C2679:二进制'<<':找不到采用类型 'overloaded-function' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误:C2679 二进制"==":未找到采用类型 'const std::string' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2678:二进制"+":未找到采用类型 'volatile A' 的左侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制"<<":未找到采用类型 'mystring' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制'>':找不到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误 C2679 二进制"=":未找到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 不是多态类型,或者为什么我们在这里需要虚拟析构函数?
- 错误 C2679 二进制"=":未找到采用类型 'int' 的右侧操作数的运算符(或者没有可接受的转换)
- 是其他类型的不同类型的初始化衍生物,或者它们是完全分开的
- 运算符重载:简单添加...错误 C2677:二进制"+":未找到采用类型 ___ 的全局运算符(或者不存在可接受的转换)
- 我可以在不声明变量类型的情况下获取输入,或者在 c++ 中为同一变量声明多个类型吗?
- 异常是否应具有标志/消息,或者每个错误应具有异常类型
- 静态嵌套bool会帮助我禁用对某些类型的调用吗?或者有更干净的方法吗
- 错误 C2677:二进制'+=':找不到采用类型 'Movie' 的全局运算符(或者没有可接受的转换)
- 错误 C2678:'=='二进制:未找到采用类型 'CSchemaString' 的左操作数的运算符(或者没有可接受的转换)
- 错误 C2679:二进制"[":未找到采用类型为"const VerseKey"的右操作数的运算符(或者没有可接受的转换)