C++ vector push_back()给出编译器错误C2280

C++ vector push_back()给出编译器错误C2280,c++,c++11,vector,c++14,C++,C++11,Vector,C++14,我试图将一个自定义类对象附加到同一类型的向量中,但是当我试图编译代码时,编译器会给出以下错误 gltf::gltf(const-gltf&):试图引用已删除的函数 我的函数以字符串(文件名)作为参数并加载该文件,然后解析该文件并填充其变量 功能如下:- void enigma::loadModel(std::string file) { gltf stagingModel; stagingModel.loadAsset(file); // populates

我试图将一个自定义类对象附加到同一类型的向量中,但是当我试图编译代码时,编译器会给出以下错误

gltf::gltf(const-gltf&):试图引用已删除的函数

我的函数以字符串(文件名)作为参数并加载该文件,然后解析该文件并填充其变量

功能如下:-

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
}
#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等级减免如下:-

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
}
#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;

};
#pragma一次
#包括
#包括
#包括
#包括
#包括“meshClass.h”
#包括“bufferClass.h”
#包括
#包括
#包括“stagingNodeClass.h”
#包括“stagingMeshClass.h”
#包括“stagingAccessorClass.h”
#包括“stagingBufferViewClass.h”
#包括“stagingImageClass.h”
#包括“stagingSamplerClass.h”
#包括“stagingTextureClass.h”
#包括“stagingMaterialClass.h”
#包括“stagingSkinClass.h”
类gltf
{
公众:
gltf();
~gltf();
矢量网格;
std::向量箱;
glm::mat4摄像机;
glm::mat4量表;
void loadAsset(标准::字符串);
私人:
std::向量stagingNode;
std::向量分级网格;
std::向量分级加载器;
std::向量stagingBufferView;
std::向量分段图像;
stagingSampler类stagingSampler;
std::向量分期结构;
std::载体分期材料;
Stagingskin类stagingSkins;
bufferClass stagingBuffer;
bool-isCamera=false;
bool节点(std::string,std::string);
int getValue(std::string);
int getCamIndex(标准::字符串);
glm::mat4 getMatrix(std::string);
glm::vec3 getVec3();
glm::vec4 getVec4();
float getFloatValue(std::string);
void initScale();
std::vector getIntArray();
std::vector getFloatArray();
std::string getName(std::string);
std::fstream资产;
std::字符串行;
};

您得到的错误是由于
gltf
是不可复制的对象,因为其复制构造函数被隐式删除。在向量上调用
push_back
需要被推的对象是可复制的或可移动的,在后一种情况下,您需要明确传递一个r值,而您没有这样做


您没有明确删除
gltf
中的复制构造函数,因此我必须假设存储在
gltf
中的一个或多个对象,或者可能存储在
gltf
中的(多个)向量中的一个对象本身是不可复制的,这导致您的类隐式删除其自己的复制构造函数。执行代码审核以找出哪个对象不可复制,然后删除它或为此类编写您自己的复制构造函数(可能还包括移动构造函数),或者将该对象改装为可正确复制。

您得到的错误是由于
gltf
是不可复制的对象,因为它的复制构造函数被隐式删除。在向量上调用
push_back
需要被推的对象是可复制的或可移动的,在后一种情况下,您需要明确传递一个r值,而您没有这样做


您没有明确删除
gltf
中的复制构造函数,因此我必须假设存储在
gltf
中的一个或多个对象,或者可能存储在
gltf
中的(多个)向量中的一个对象本身是不可复制的,这导致您的类隐式删除其自己的复制构造函数。执行代码审核以找出哪个对象不可复制,然后删除它或为此类编写您自己的复制构造函数(可能还包括移动构造函数),或者将该对象改装为可正确复制的对象。

gltf
不可复制,它可能至少有一个成员,
资产
,这是不可复制的。错误消息告诉您,
gltf
未定义复制构造函数。您应该编写一个复制构造函数(请记住),或者定义一个移动构造函数(将您带到),然后
push_back(std::move(stagingModel))@FrançoisAndrieux但是什么让它不可复制?有办法解决这个问题吗?
gltf
不可复制,它可能至少有一个成员,
asset
不可复制。错误消息告诉您,
gltf
没有定义复制构造函数。您应该编写一个复制构造函数(请记住),或者定义一个移动构造函数(将您带到),然后
push_back(std::move(stagingModel))@FrançoisAndrieux但是什么让它不可复制?有办法解决这个问题吗?以前我可以使用这个类来加载3d模型(不使用该类的向量),所以我假设不可复制的成员是gltf的直接成员(可能是评论中提到的资产),我会修改代码并在这里给出反馈。我创建了一个显式的复制构造函数,它成功了,感谢您的帮助以前我可以使用这个类加载3d模型(不使用类的向量),所以我假设不可复制的成员是gltf的直接成员(可能是评论中提到的资产),我将修改代码并在这里给出反馈。我创建了一个显式的复制构造函数,它成功了,谢谢你的帮助