Я продолжаю получать ошибку C2280 при попытке добавить объект к вектору класса типа. Ниже перечислены файлы, которые дают мне ошибкуПолучение ошибки C2280 при попытке добавить объект к вектору
'interfaceText::interfaceText(const interfaceText &)': attempting to reference a deleted function"
interfaceText.h
#include<SFML/Graphics.hpp>
#include<vector>
#include<iostream>
#include<math.h>
#include<sstream>
#include<ctime>
#include<cstdlib>
class interfaceText{
private:
std::string createString();
std::ostringstream stringStream;
sf::Text text;
sf::Vector2f position;
sf::Font font;
sf::Color color;
//DEBUG
int currentAngle = 1;
sf::Color generateRandomColors();
public:
sf::Text returnRenderObject();
interfaceText(sf::Vector2f textPosition, sf::Color textColor);
void updateText(float currentangle);//std::string string, sf::Vector2f textPosition, sf::Color textColor);
};
extern std::vector<interfaceText> textArray;
interfaceText.cpp
#include "interfaceText.h"
interfaceText::interfaceText(sf::Vector2f textPosition, sf::Color textColor):position(textPosition),color(textColor){
font.loadFromFile("AvenirNextLTPro-Cn.otf");
text.setString(createString());
text.setPosition(position);
text.setFont(font);
text.setColor(color);
textArray.push_back(*this); //<-Code that causes error?
}
std::string interfaceText::createString() {
std::string TESTSTRING="DEBUG";
return TESTSTRING;
}
void interfaceText::updateText(float currentAngle){//std::string string, sf::Vector2f textPosition, sf::Color textColor) {
text.setString(createString());
position.x = (cos(currentAngle*3.14/180)* position.x/2);
position.y = (sin(currentAngle*3.14/180)* position.y/ 2);
text.setPosition(position);
text.setColor(generateRandomColors());
//std::cout << text.getPosition().x<<" " << text.getPosition().y <<'\n';
currentAngle+=1;
}
sf::Text interfaceText::returnRenderObject() {
return text;
}
sf::Color interfaceText::generateRandomColors() {
srand(time(NULL));
sf::Color newColor (rand()%255, rand() % 255, rand() % 255,255);
return newColor;
}
An в main.cpp (это она не все это потому, что Я удалил код, который я счел несущественным)
#include"interfaceText.h"
#include<vector>
int main(){
interfaceText newText(sf::Vector2f(100, 100), sf::Color(255, 255, 255, 255));
return 0;
}
Я уверен, что код, который вызывает эту ошибку (или, по меньшей мере, запуская компилятор выдаст сообщение об ошибке) является
textArray.push_back(*this);
в interfaceText.cpp файл
Есть также некоторые примечания, приведенные с сообщением об ошибке, как показано ниже:
note: compiler has generated 'interfaceText::interfaceText' here
see reference to function template instantiation 'void std::allocator<_Ty>::construct<_Objty,interfaceText&>(_Objty *,interfaceText &)' being compiled
из нот я заключаю, что компилятор пытается добавить новый CTOR для interfaceText
класса, но я не знаю, почему
Отсутствует конструктор по умолчанию для 'interfaceText'? –
@ πάνταῥεῖ Я ранее пытался добавить конструктор по умолчанию, но это не решило проблему. Спасибо за вашу помощь, хотя – ThomasMartin