我试图将自定义类对象附加到相同类型的向量上,但是当我尝试编译我的代码时,编译器给出以下错误
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;
};
答案 0 :(得分:5)
您得到的错误是gltf
是不可复制对象的结果,因为它的副本构造函数被隐式删除。在向量上调用push_back
要求被推送的对象是可复制的或可移动的,在后一种情况下,您需要明确传递一个不做的r值。
您尚未在gltf
中明确删除副本构造函数,因此我想假设是gltf
中存储的一个或多个对象,或者可能是gltf
中存储的对象之一import { Action, Reducer } from 'redux';
// -----------------
// STATE - This defines the type of data maintained in the Redux store.
export interface LoggedInUserState {
userName: string,
isAdmin: boolean,
isUserManager: boolean
}
中的(许多)向量本身是不可复制的,这导致您的类隐式删除其自己的副本构造函数。进行代码审核以找出哪个对象不可复制,然后删除该对象或为此类编写自己的副本构造函数(可能还会移动构造函数),或对该对象进行改造以使其可正确复制。