[英]vector push_back() gives the compiler error C2280
我試圖將自定義類對象附加到相同類型的向量中,但是當我嘗試編譯代碼時,編譯器給出以下錯誤
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
是不可復制對象的結果,因為它的副本構造函數被隱式刪除。 在向量上調用push_back
要求被推送的對象是可復制的或可移動的,在后一種情況下,您需要明確傳遞一個r值,而您並沒有這樣做。
您尚未在gltf
明確刪除副本構造gltf
,因此我必須假定的是,存儲在gltf
中的一個或多個對象,或者可能存儲在gltf
中的(許多)向量中的對象之一本身gltf
可復制的,這導致您的類隱式刪除其自己的副本構造函數。 進行代碼審核以找出哪個對象不可復制,然后刪除該對象或為此類編寫自己的復制構造函數(可能還會移動構造函數),或對該對象進行改造以使其可正確復制。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.