私は課題を持っていますが、サブクラスになる2種類の質問の抽象的なベースクラスを作成するなど、いくつかの要求がありました。また、3つのクラスには2つのコンストラクタがあり、デストラクタのみが空である。コンストラクタの反乱?何が起こっていますか?
MultipleAnswerQuestion::MultipleAnswerQuestion(string question, string alternatives[],
int alternativeAmount, int correctAnswer):Question(question)
{
for(int i=0; i<alternativeAmount; i++){
this->alternatives[i] = alternatives[i]; //string
}
this->alternativeAmount = alternativeAmount; //int
this->correctAnswer = correctAnswer; //int
}
MultipleAnswerQuestion::MultipleAnswerQuestion()
{
for(int i=0; i<alternativeAmount; i++){
this->alternatives[i] = ""; //string
}
this->alternativeAmount = NULL; //int
this->correctAnswer = NULL; //int
}
そして:
Question::Question(string question)
{
this->question = question;
}
Question::Question()
{
this->question = "N/A";
}
とは "MultipleAnswerQuestion" と呼ばれるサブクラスの一つで、私はこれをやってみてください。
は、だから私は質問(基底クラス)の.cppファイルでこれをやりました "IntelliSense:クラス"質問 "に複数の既定のコンストラクタがあります"質問には複数の既定のコンストラクタがあります。 "というエラーメッセージがMultipleAnswerQuestionの下部コンストラクタに表示されます。
何が問題ですか?これをどうすれば解決できますか?
コンストラクタを記入し、2つのコンストラクタを使用することが要求されるため、削除することはできません。
EDIT クラスの宣言:
class Question
{
public:
Question();
Question(string question = "N/A");
virtual ~Question();
void setQuestion(const string &question);
string getQuestion() const;
void print() const;
virtual void printSpec() const=0;
private:
string question;
};
そしてMultipleAnswerQuestion:
const int MAX = 6;
class MultipleAnswerQuestion :
public Question
{
public:
MultipleAnswerQuestion();
MultipleAnswerQuestion(string question, string alternatives[], int alternativeAmount, int correctAnswer);
virtual ~MultipleAnswerQuestion();
void printSpec() const;
void setCorrectAnswer(int correctAnswer);
void setAlternative(int alternativeNr, string alternative);
private:
int correctAnswer;
string alternatives[MAX];
int alternativeAmount;
};
他に何もなければ[MCVE]の一部として実際のコンパイルを試してください。 – LogicStuff
'Question'の*宣言*を教えてください。なぜなら、問題がどこにあるからですか。 .cppコードはそれがなければ役に立たない。 –
さて、ここで間違っているのは、C++の基礎を学び理解するための代替えとして、オーバーベース化されたIDEによって提供される松葉杖を使用することに依存していることです。プレーンテキストエディタとコマンドラインコンパイラを使って、C++をどうやって学ぼうとしたのか、私には不思議に思えます。 –