How to store values from previous classes into a vector in c++?


Keywords:c++ 


Question: 

I am new to programming and i am currently stuck on a problem. I am currently stuck on how to save the input values to be saved in a vector after passing through the Tasklist class.

Class task

class{void Task::description(){
string descrip;

cout<< "How would you describe this task" <<endl;
getline(cin, descrip);
cin.ignore();

}

void Task::deadline(){
int due;

cout<< "In how many days is task due?"<<endl;
cin >> due;
}

class EventTask

void EventTask::locatioin(){
string location;

cout<< "Where is the event taking place?"<<endl;
getline(cin,location);
cin.ignore();


 }

void EventTask::time(){
string time;

cout<< "What time is the event?"<<endl;
getline(cin,time);
cin.ignore();
}

class TaskList

   void Tasklist::Add_Task()
 {

string add_cmd;
cout<< "What type of Task is this? [G: Generic, E: Event]"<<endl;
cin>> add_cmd;

if (add_cmd == "g"){
    Task t;
    t.deadline();
    t.description();

}
    if (add_cmd == "e"){
    EventTask et;
    et.deadline();
    et.description();
    et.locatioin();
    et.time();

    }

main.cpp

int main(){

 Tasklist tl;
 tl.Add_Task();}

my main question is how do I go about saving the the input values into a vector and then later output what is contained within the vector.


1 Answer: 

you can use C++ class inheritance feature and define strings as private variables for the Task class, something like this:

 class Task{
  private:
string location;
string add_cmd;
string description;
public:
//.... functions to set and get variable's value plus other functions  

    like description(), location() and Add_Task() ....
}
class EventTask: public Task {
...
}
class TaskList: public Task {
....
}

int main() {
...
}