C++矢量错误 C2036:"整数 (*)[]":未知大小
C++ vector error C2036: 'int (*)[]' : unknown size
>我收到 5 个编译错误
C2036: "整数 (*)[]" : 未知大小
全部来自向量类中的不同位置。
#include <glglew.h>
#include "Vector2.h"
#include "Vector3.h"
#include "WFObjModel.h"
#include <vector>
#include <memory>
using namespace math;
using std::vector;
using std::string;
using io::WFObjModel;
using std::unique_ptr;
class Mesh
{
private:
GLuint textureID;
unique_ptr<vector<Vector3<float>>> m_vertices;
unique_ptr<vector<Vector3<float>>> m_normals;
unique_ptr<vector<Vector2<float>>> m_textureCoordinates;
unique_ptr<vector<int[]>> m_indices;
public:
Mesh(unique_ptr<vector<Vector3<float>>> vertices,
unique_ptr<vector<Vector3<float>>> normals,
unique_ptr<vector<Vector2<float>>> textureCoordinates,
unique_ptr<vector<int[]>> indices);
Mesh(Mesh&& other){
m_vertices = std::move(other.m_vertices);
m_normals = std::move(other.m_normals);
m_textureCoordinates = std::move(other.m_textureCoordinates);
m_indices = std::move(other.m_indices);
}
Mesh& operator=(Mesh&& other)
{
m_vertices = std::move(other.m_vertices);
m_normals = std::move(other.m_normals);
m_textureCoordinates = std::move(other.m_textureCoordinates);
m_indices = std::move(other.m_indices);
return *this;
}
我已经查看了围绕此问题的其他答案,但接受的解决方案似乎不起作用/不适用。
错误 C2036:"代理 *const":"矢量"类中的大小未知和定义向量类型时出现前向声明错误?
似乎暗示该错误是由于编译器没有对存储在向量中的类型进行完整定义。我有一个包含存储在向量中的仅标题模板类,但我猜这与模板类的编译方式有关?
我似乎无法为模板添加前向声明 class Vector3<float>
编译器认为我正在尝试专门化模板。
你的问题来自这一行:
unique_ptr<vector<int[]>> m_indices;
您应该改用 stl 容器,在这种情况下,它可以是向量的向量
另外,在这种情况下为什么需要unique_ptr? 向量支持移动语义,你可以有一个
vector<vector<int>> m_indices;
关于移动构造函数的额外提示,通常的做法是像这样实现它们:
Mesh(Mesh&& other)
: m_vertices(std::move(other.m_vertices)
, m_normals(std::move(other.m_normals))
, textureCoordinates(std::move(other.m_textureCoordinates))
, indices(std::move(other.m_indices))
{ }
相关文章:
- 如何反转整数参数包
- enum是C++中的宏变量还是整数变量
- 努力将整数转换为链表。不知道我在这里做错了什么
- 整数不会重复超过随机数
- 在C++中手动调整数组大小
- 检查输入是否不是整数或数字
- C++使用整数的压缩数组初始化对象
- 继承期间显示未知行为的子类
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 比较两个整数在C++中与未知 int 类型的相等性
- C++ 读取未知数量的整数到 cin 并输出总和
- 获取由空格分隔的未知大小的单行输入,并将其存储到整数数组中
- 保存未知数量的整数,而不会花费太多时间/内存
- 将未知大小的整数转换为其无符号形式的最短/最干净方法
- 如何将.txt文件中的未知数字整数保存到数组中
- 如何找到未知整数类型的最大值
- dev C++ 读取固定数量的整数行,每行中整数数量未知
- 输入一个未知的整数流,并对其进行整数运算
- 未知位大小的模板化整数
- C++矢量错误 C2036:"整数 (*)[]":未知大小