Note that there are some explanatory texts on larger screens.

plurals
  1. POValues not passing properly?
    text
    copied!<p>I've been working on this project for a while, it's a new language for me but I had a partner with experience who kinda ditched me. Anyways, right now I'm having trouble with getting the text from one object to another. I instantiate an object in the game class, then try to get it and save it to another object in the main class but when I get the object it's empty! I don't know what's going on here and I just can't seem to figure it out.</p> <p>but the part that isn't working is in the display method when I try to draw the questions text:</p> <pre><code>drawText((WinWidth/2)-225, (WinHeight/2) - 90, curQuestion.question.c_str()); </code></pre> <p>curQuestion is created at the top but instantiated in the mouse method:</p> <pre><code>curQuestion = g.getQuestion(col,row); </code></pre> <p>and here's the game class (which is in Cc.h)</p> <pre><code>class Game { public: Game(bool); void initQuestions(); Question getQuestion(int, int); string getQuestionText(int, int); private: Question questions[5][5]; }; Game::Game(bool m) { mp = m; initQuestions(); } void Game::initQuestions() { bool hasDouble = false; srand( time(NULL)); int blarg = rand() % 25 + 1; fstream questionFile; questionFile.open("questions.txt", ifstream::in); int cur = 0; for(int c = 0; c &lt; 5; c++) { for(int r = 0; r &lt; 5; r++) { char * q = new char[256]; char * a = new char[256]; questionFile.getline(q,256); questionFile.getline(a,256); questions[c][r] = Question(c,r, false, q, a); cout &lt;&lt; questions[c][r].question.c_str() &lt;&lt; questions[c][r].answer.c_str(); } } questionFile.close(); } Question Game::getQuestion(int c, int r) { return questions[c][r]; } string Game::getQuestionText(int c, int r) { return questions[c][r].question; } </code></pre> <p>Note: the cout called in the game method does return exactly what it should!</p> <p>Question class:</p> <pre><code>class Question { public: int col; int row; bool dailyDouble; string question; string answer; int value; Question(); Question(int, int, bool, string, string); bool checkAnswer(string); string getQuestion(); }; Question::Question() { } Question::Question(int c, int r, bool d,string q, string a) { col = c; row = r; dailyDouble = d; question = q, answer = a; cout &lt;&lt; "TEST&gt; Q: " &lt;&lt; question &lt;&lt; ", A: " &lt;&lt; answer &lt;&lt; endl; if(d) value = r * 200 * 2; else value = r * 200; } bool Question::checkAnswer(string answer) { if(answer.find("What is") &amp;&amp; answer.find(answer)) return true; return false; } string Question::getQuestion() { return question; } </code></pre> <p>I really can't understand what's going wrong here, any help is greatly appreciated. I hope that once I figure out what's going wrong here I'll be able to finish on my own!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload