I've been looking through a lot of old posts and still can't seem to figure out what I'm doing wrong. Would appreciate any help refactoring this into code that will work.
I'm getting an error in my quizquestion.h
file stating that object of abstract type "Answer" is not allowed
due to Answers::getAnswers
being a pure virtual function. I can't figure out how I should go about making the code work. From what I can tell, it looks like I'm overloading the purely virtual function correctly in the Answer
class, but this must clearly not be the case. This is what I currently have:
quizquestion.h
#ifndef QuizQuestion_h
#define QuizQuestion_h
#include "answerdata.h"
#include "answer.h"
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
class QuizQuestion {
public:
QuizQuestion();
QuizQuestion(int num);
void getQuestion(std::ostream& outs);
void getAnswers(std::ostream& outs);
void setQuestion(std::string q);
void setAnswers();
int setAnswersMenu();
void getMenu();
private:
std::string question;
Answer answers;
};
#endif
answers.h
#ifndef Answer_h
#define Answer_h
#include "answerdata.h"
#include <vector>
class Answer {
public:
Answer * Create(int num);
virtual void getAnswers(std::ostream& outs) = 0;
};
class TrueOrFalse:public Answer {
public:
TrueOrFalse();
void getAnswers(std::ostream& outs) override;
private:
AnswerData answers[2];
};
class MultipleChoice:public Answer {
public:
MultipleChoice();
void getAnswers(std::ostream& outs) override;
private:
std::vector<AnswerData> answers;
};
class MatchAnswers:public Answer {
public:
MatchAnswers();
void getAnswers(std::ostream& outs) override;
private:
std::vector<AnswerData> answers;
};
#endif