【发布时间】:2018-08-01 19:26:58
【问题描述】:
我正在尝试将自定义类对象附加到相同类型的向量中,但是当我尝试编译我的代码时,编译器会给出以下错误
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
}
我的 gltf 类声明如下:-
#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;
};
【问题讨论】:
-
gltf不可复制,它可能至少有一个成员asset,这是不可复制的。 -
错误信息告诉您
gltf没有定义复制构造函数。您应该编写一个复制构造函数(记住rule-of-three),或定义一个移动构造函数(将您带到rule-of-five)然后push_back(std::move(stagingModel)); -
@FrançoisAndrieux 但是是什么让它不可复制?有没有办法解决这个问题?