Using the Constructor to create a class

I’m having a hard time creating a class using the constructor. Not sure what’s happening. Sometimes it loads, sometimes it doesn’t; not sure what’s going on.
This is my .h from that class:

ScreenBasics(int _answersFader, int _answersFaderVel, ofPoint _answersPos, size_t _numberOfanswers, string *_answersText, ofPoint _questionPos, string _questionText, bool _isHovered, bool _isClicked);

And this is my .cpp from that class:

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

And this is how I create it on my 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);

Sometimes when I create the app it thrown me this error:
libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc.

Any thoughts?

I don’t know if it has to do, but in your constructor declaration (.h file) the last argument is bool _isClicked
in the constructor implementation (.cpp file) the last argument is string _pathToFont.
Check if your compiler supports that.
Best!

@kovic thanks for your reply. I figured it out and that wasn’t the problem. The problem is that I had a leak of memory in answerText. So initially in my constructor I set it to:

answersText(new string[numberOfAnswers])

And then inside, I pass it the value of:

answersText = _answersText;

That was creating the problem. Somebody highlighted that it was poor design. So I came up with something better:

ScreenBasics::ScreenBasics(int _questionFader, int _questionFaderVel,int _answersFader, int _answersFaderVel, ofPoint _answersPos, size_t _numberOfAnswers,ofPoint _questionPos, bool _isHovered, bool _isClicked):questionFader(_questionFader), questionFaderVel(_questionFaderVel),answersFader(_answersFader), answersFaderVel(_answersFaderVel), answersPos(_answersPos), numberOfAnswers(_numberOfAnswers),questionPos(_questionPos), isHovered(_isHovered), isClicked(_isClicked){

}

Got rid of all the strings in the constructor and created a separate function that takes care of that:

void ScreenBasics::setup(string &_questionText, string *_answersText, string &pathToFont ){

questionText = _questionText;
question.loadFont(pathToFont, 28);
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);
        //we pass the strings
        answersText.push_back(_answersText[i]);
    }   

}

This worked perfectly BTW.