我很难使用构造函数创建一个类。不确定发生了什么。有时它会加载,有时它不会加载;不知道发生了什么。 这是我班上的.h:
ScreenBasics(int _answersFader, int _answersFaderVel, ofPoint _answersPos, size_t _numberOfanswers, string *_answersText, ofPoint _questionPos, string _questionText, bool _isHovered, bool _isClicked);
这是我班上的.cpp:
ScreenBasics::ScreenBasics(int _answersFader, int _answersFaderVel, ofPoint _answersPos, size_t _numberOfAnswers, string *_answersText, ofPoint _questionPos, string _questionText, bool _isHovered, bool _isClicked, string _pathToFont):answersFader(_answersFader), answersFaderVel(_answersFaderVel), answersPos(_answersPos), numberOfAnswers(_numberOfAnswers),answersText(new string[numberOfAnswers]),questionPos(_questionPos), isHovered(_isHovered), isClicked(_isClicked){
answersText = _answersText;
for(int i = 0; i < numberOfAnswers; i++){
//we create our text
ofTrueTypeFont tmp;
answers.push_back(tmp);
answers[i].loadFont(_pathToFont, 24);
// we create our boundary box
ofRectangle box;
answersBox.push_back(box);
}
}
这就是我在我的ofApp.cpp上创建它的方式:
int answersFader3 = 0;
int answersFader3Vel = 2;
ofPoint answersPos3 = ofPoint(( width / 2 ) - ( width / 10 ),( height / 2 ) - ( height / 5 ));
size_t numberOfAnswers3 = 3;
string answersText3[] = {"1.Unisex", "2. Female", "3.Male"};
ofPoint questionPos3 = ofPoint(( width / 2 ) - ( width / 8), ( height / 2) - ( height / 3 ));
string questionText3 = "What Gender's perfume are you looking for?";
bool isHovered3 = false;
bool isClicked3 = false;
// screen3 was created as a pointer in the .h file ScreenBasics *screen3;
screen3 = new ScreenBasics(answersFader3, answersFader3Vel, answersPos3, numberOfAnswers3, answersText3, questionPos3, questionText3, isHovered3, isClicked3, pathToFont);
有时当我创建应用程序时,它会抛出这个错误: libc ++ abi.dylib:以std :: bad_alloc类型的未捕获异常终止:std :: bad_alloc。
有什么想法吗?