I have to make a class with the ability to allow a user to designate how many questions they wish to ask and then have the user write each question down. How would I go about this? I have tried using dynamic memory allocation on string objects, but have received issues with the ">>" operator when I allow the user to ask the question.
#pragma once
#include<iostream>
#include<string>
using namespace std;
class TestGenerator
{
private:
int index;
string** question;
void AskQuestions(); //Needs work
void AskIndex();
public:
TestGenerator();
{
this->question = new string*[index];
this->index = 0;
}
TestGenerator(int, string**);
TestGenerator(const TestGenerator& aTest);
~TestGenerator();
{
for (int i = 0; i < index; i++)
{
delete this->question[i];
this->question[i] = nullptr;
}
delete[] this->question;
this->question = nullptr;
}
TestGenerator& operator= (const TestGenerator& aTest);
void setQuestions(string**);
void setIndex(int);
string** GetQuestions() const;
int GetIndex() const;
void AskAll();
void ShowIndex()const;
void ShowQuestions()const;
void ShowAll()const;
friend ostream& operator << (ostream& out, const TestGenerator& aTest);
friend istream& operator >> (istream& in, TestGenerator& aTest);
};
void TestGenerator::AskQuestions()
{
for (int i = 0; i < index; i++)
{
cin >> this->question[i];
}
}
istream& operator>>(istream& in, TestGenerator& aTest)
{
in >> aTest.AskAll();
return(in);
}
void TestGenerator::AskAll()
{
this->AskIndex();
this->AskQuestions();
}
It is giving me an error E0349 with the operator ">>"