title: Splitting up classes c++
body: <p>I'm facing a problem for the past couple of days.</p>
  
  <p>First of all, I had a project that I've done. But now I've to split it's classes.</p>
  
  <p>Here's how I split the classes (a class as an example):</p>
  
  <p>Header file:</p>
  
  <pre><code>#ifndef QUESTION_H
  #define QUESTION_H
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include "Answer.h"
  using namespace std;
  
  // Name -- hold a first and last name
  class Question {
  protected:
     string type;   // Type of the question, e.g MC or TF
     string text;   // Text of the question
  public:
     // Default constructor
     Question ();
  
     // Getters and setters
     string getType();
     string getText();
     void setType (string t);
     void setText (string t);
  
     // displayText -- Display the text of the question, unformatted at present
     void displayText();
  
     // Template pattern -- algorithm in parent which does its work calling child methods
     virtual void displayAnswers();
     virtual void display ();
  
     // Virtual pure functions that must be implemented by each derived class
  
     virtual int grade (Answer*);              // grade a given answer
     virtual Answer* readAnswer(istream &amp;);     // read a user's answer
  };
  
  #endif
  </code></pre>
  
  <p>Alright, now here is the implementation:</p>
  
  <pre><code>#include "Question.h"
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  using namespace std;
  
     Question::Question () { type = ""; text = ""; }
  
     // Getters and setters
     string Question::getType() { return type; }
     string Question::getText() { return text; }
     void Question::setType (string t) { type = t; }
     void Question::setText (string t) { text = t; }
  
     // displayText -- Display the text of the question, unformatted at present
     void Question::displayText() {
        cout &lt;&lt; text;
     }
     // Template pattern -- algorithm in parent which does its work calling child methods
     void Question::displayAnswers(){ }// Require derived classes to implement
     void Question::display () {   
       Question::displayText();
       Question::displayAnswers();   // Call derived class's displayAnswers 
     }
  
     // Virtual pure functions that must be implemented by each derived class
  
     int Question::grade (Answer*){ return 0; }              // grade a given answer
     Answer* Question::readAnswer(istream &amp;){ return 0; }    // read a user's answer
  </code></pre>
  
  <p>Ok, so I've done the other classes the same exact way.</p>
  
  <p>Now what's left is the MakeFile, here it is:</p>
  
  <pre><code>project: Question MCQuestion TFQuestion Answer IntAnswer CharAnswer Main
      g++ -std=c++11 Question MCQuestion TFQuestion Answer IntAnswer CharAnswer Main -o project
  .cc.o:
      g++ -std=c++11 -c &lt;−o@
  </code></pre>
  
  <p>Now when I try running <code>make</code> it brings up this message:</p>
  
  <pre><code>g++     Question.cpp   -o Question
  /usr/lib/gcc/i586-suse-linux/4.7/../../../crt1.o: In function `_start':
  /home/abuild/rpmbuild/BUILD/glibc-2.17/csu/../sysdeps/i386/start.S:113: undefined reference to `main'
  collect2: error: ld returned 1 exit status
  make: *** [Question] Error 1
  </code></pre>
  
  <p>Can somebody explains it? or what am I doing wrong?</p>
  
  <p>Thanks.</p>
  
  <hr>
  
  <p><strong>Edited:</strong></p>
  
  <p>Main.cc :</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include "Question.h"
  #include "MCQuestion.h"
  #include "TFQuestion.h"
  #include "Answer.h"
  #include "IntAnswer.h"
  #include "CharAnswer.h"
  #include &lt;vector&gt;
  using namespace std;
  
  
  int main () {
     vector&lt;Question *&gt; questions;         // Holds pointers to all the questions
     ifstream infile ("questions.txt");    // Open the input file
     int totalCorrect = 0;                 // Initialize the count from number of correct answers
  
     // Read each question and place it into the questions vector
     string questionType;
     while ( getline (infile, questionType) ) {
        if (questionType == "MC")  {               
           MCQuestion *mc = new MCQuestion();
           mc-&gt;read(infile);    
           questions.push_back(mc);
        }
        else if ( questionType[0]  == 'T' or questionType[0] == 'F' ) {
           TFQuestion* tf = new TFQuestion();
           tf-&gt;read(infile);
           tf-&gt;setAnswer(questionType[0]);
           questions.push_back(tf);
        }
        else {
           cout &lt;&lt; "Input file is corrupt. Expected to find MC, T or F; found \"" &lt;&lt; questionType &lt;&lt; "\" instead." &lt;&lt; endl;
        }
     }
     infile.close();
  
     // Pose each question, read and grade answers, tally total
  
     int questionNo = 0;
     for (auto &amp;question: questions) { 
  
        // Pose the question
        questionNo++; cout &lt;&lt; questionNo &lt;&lt; ".  ";
        question-&gt;display();
  
        // Get the user's answer
        Answer* ans = question-&gt;readAnswer(cin);
  
        // Grade it and increment total
        int correct = question-&gt;grade(ans);
        totalCorrect = totalCorrect + correct
  
        // Inform the user as to whether or not they got the question correct
        cout &lt;&lt; "Your answer was " &lt;&lt; (correct?"":"not ") &lt;&lt; "correct\n" &lt;&lt; endl;
  
     }
  
     // Print the overall score
     cout &lt;&lt; "Your overall score is " &lt;&lt; totalCorrect &lt;&lt; "/" 
          &lt;&lt; questions.size()  &lt;&lt; endl;
  
     return 0;
  
  }
  </code></pre>