Why is my data member empty even after construction?
<p>I have included both my definition of the Question class and its implementation, the first is a header file and the second a cpp file.</p>

<p>I put comments in to show where the problem is.  For some reason under the constructor I can cout the questionText just fine but when I try to do this under the getQuestionText function it just outputs an empty string?  Any help would be most appreciated!! Thanks!</p>

<pre><code>#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;

using namespace std;

#ifndef QUESTION_H
#define QUESTION_H

class Question{
public:
    Question(int thePointValue, int theChapterNumber, \
        string theQuestionText);
    int getPointValue() const;
    int getChapterNumber() const;
    string getQuestionText() const;
    virtual void writeQuestion(ostream&amp; outfile) const;
    virtual void writeKey(ostream&amp; outfile) const;

private:
    int pointValue;
    int chapterNumber;
    string questionText;

    void writePointValue(ostream&amp; outfile) const;
};




#endif





#include "Question.h"

Question::Question(int thePointValue, int theChapterNumber, \
        string theQuestionText)
{
    pointValue = thePointValue;
    chapterNumber = theChapterNumber;
    questionText = theQuestionText;

        //HERE THIS WORKS PERFECTLY
        cout &lt;&lt; questionText &lt;&lt; endl;
}

int Question::getPointValue() const
{
    return pointValue;
}

int Question::getChapterNumber() const
{
    return chapterNumber;
}

string Question::getQuestionText() const
{
        //THIS IS THE PROBLEM. HERE IT OUPUTS AN EMPTY STRING NO MATTER WHAT!
        cout &lt;&lt; questionText &lt;&lt; endl;
    return questionText;
}

void Question::writeQuestion(ostream&amp; outfile) const
{
    writePointValue(outfile);
    outfile &lt;&lt; questionText &lt;&lt; endl;
}

void Question::writeKey(ostream&amp; outfile) const
{
    writePointValue(outfile);
    outfile &lt;&lt; endl;
}

void Question::writePointValue(ostream&amp; outfile) const
{
    string pt_noun;

    if (pointValue == 1)
        pt_noun = "point";
    else
        pt_noun = "points";

    outfile &lt;&lt; "(" &lt;&lt; pointValue &lt;&lt; " " &lt;&lt; pt_noun &lt;&lt; ") ";
}

vector&lt;Question *&gt; QuestionsList(string filename, int min, int max)
{
vector&lt;Question *&gt; QuestionList;

string line;
vector&lt;string&gt; text;
ifstream in_file;
in_file.open(filename.c_str());
while (getline(in_file, line))
{
    text.push_back(line);
}

string type;
for(int i = 0; i &lt; text.size(); i ++)
{
    int num = text[i].find('@');
    type = text[i].substr(0, num);
    if (type == "multiple")
    {
        MultipleChoiceQuestion myq = matchup(text[i]);
        MultipleChoiceQuestion* myptr = &amp;myq;
        if (myq.getChapterNumber() &gt;= min &amp;&amp; myq.getChapterNumber() &lt;= max)
        {
            QuestionList.push_back(myptr);
        }
    }
    if (type == "short")
    {
        ShortAnswerQuestion myq = SAmatchup(text[i]);
        ShortAnswerQuestion* myptr = &amp;myq;
        if (myq.getChapterNumber() &gt;= min &amp;&amp; myq.getChapterNumber() &lt;= max)
        {
            QuestionList.push_back(myptr);
        }
    }
    if (type == "long")
    {
        LongAnswerQuestion myq = LAmatchup(text[i]);
        LongAnswerQuestion* myptr = &amp;myq;
        if (myq.getChapterNumber() &gt;= min &amp;&amp; myq.getChapterNumber() &lt;= max)
        {
            QuestionList.push_back(myptr);
        }
    }
    if (type == "code")
    {
        CodeQuestion myq = CODEmatchup(text[i]);
        CodeQuestion* myptr = &amp;myq;
        if (myq.getChapterNumber() &gt;= min &amp;&amp; myq.getChapterNumber() &lt;= max)
        {
            QuestionList.push_back(myptr);
        }
    }
    cout &lt;&lt; QuestionList[QuestionList.size()-1]-&gt;getQuestionText() &lt;&lt; endl;
}
for (int i = 0; i &lt; QuestionList.size(); i ++)
{
    int numm = QuestionList.size();
    cout &lt;&lt; QuestionList[numm-1]-&gt;getQuestionText() &lt;&lt; endl;
}
return QuestionList;
</code></pre>

<p>}</p>

<p>then when i call this in main the code breaks</p>

<pre><code>vector&lt;Question *&gt; list = QuestionsList(pool_filename, min_chapter, max_chapter);
cout &lt;&lt; list[0]-&gt;getQuestionText() &lt;&lt; endl;
</code></pre>
