Bul*_*Bul 0 c++ vector c++11 c++14
我试图将自定义类对象附加到相同类型的向量,但是当我尝试编译我的代码时,编译器给出以下错误
gltf::gltf(const gltf &): attempting to reference a deleted function
我的函数接受一个字符串(文件名)作为参数并加载该文件,然后解析该文件并填充它的变量
功能如下: -
void enigma::loadModel(std::string file)
{
gltf stagingModel;
stagingModel.loadAsset(file); // populates my object with data
model.push_back(stagingModel); // appends the populated object to a vector array (this line generates the error)
.... // the rest of the code
}
Run Code Online (Sandbox Code Playgroud)
我的gltf类decleration如下: -
#pragma once
#include <iostream>
#include <vector>
#include <sstream>
#include <fstream>
#include "meshClass.h"
#include "bufferClass.h"
#include <gtx/quaternion.hpp>
#include <gtx/transform.hpp>
#include"stagingNodeClass.h"
#include"stagingMeshClass.h"
#include"stagingAccessorClass.h"
#include"stagingBufferViewClass.h"
#include"stagingImageClass.h"
#include"stagingSamplerClass.h"
#include"stagingTextureClass.h"
#include"stagingMaterialClass.h"
#include"stagingSkinClass.h"
class gltf
{
public:
gltf();
~gltf();
std::vector<meshClass> mesh;
std::vector<char> bin;
glm::mat4 camera;
glm::mat4 scale;
void loadAsset(std::string);
private:
std::vector<stagingNodeClass> stagingNode;
std::vector<stagingMeshClass> stagingMesh;
std::vector<stagingAccessorClass> stagingAccessor;
std::vector<stagingBufferViewClass> stagingBufferView;
std::vector<stagingImageClass> stagingImage;
stagingSamplerClass stagingSampler;
std::vector<stagingTextureClass> stagingTexture;
std::vector<stagingMaterialClass> stagingMaterial;
stagingSkinClass stagingSkins;
bufferClass stagingBuffer;
bool isCamera = false;
bool node(std::string, std::string);
int getValue(std::string);
int getCamIndex(std::string);
glm::mat4 getMatrix(std::string);
glm::vec3 getVec3();
glm::vec4 getVec4();
float getFloatValue(std::string);
void initScale();
std::vector<int> getIntArray();
std::vector<float> getFloatArray();
std::string getName(std::string);
std::fstream asset;
std::string line;
};
Run Code Online (Sandbox Code Playgroud)
您获得的错误是gltf作为不可复制对象的结果,因为它的复制构造函数被隐式删除.调用push_back向量要求被推送的对象可以是可复制的或可移动的,在后一种情况下,你需要明确地传递一个你没有做过的r值.
你没有明确删除拷贝构造函数gltf,所以我必须假设存储在一个或多个对象中gltf,或者可能存储在(很多)向量内的对象之一gltf,本身是不可复制的,导致您的类隐式删除自己的复制构造函数.执行代码审计以找出哪个对象不可复制,并为此类删除它或编写自己的复制构造函数(可能还有移动构造函数),或者将该对象改进为可正确复制.
| 归档时间: |
|
| 查看次数: |
133 次 |
| 最近记录: |