Hi. I've got an assignment today, and I'm having trouble with doing it...
The assignment is..
1. Make 3 functions.
2. "add" function saves data.
3. "getSize" function counts the number of data.
4. "output" function outputs data in "add" data.
I've tried for 2 hours and I ended up with a few questions.
1. How can I output in "output" function data from "add" function?
2. Where should I declare dynamic allocation?
3. Why should I count the number of data...?
template<typename T>
std::vector<T> add()//the function returns a vector of all the data you've added
{
//declare the vector
//have a loop to enter data unless user chooses to quit
//or ask user upfront how many elements s/he wants to enter
//push_back vector with the data entered
//when user's done return the vector
//local variable, so return by value
//
}
vector.size() counts number of data
range loop (C++11, google if necessary) over the vector to output it's data assuming opertor << is defined for the datatype, otherwise you have to provide an overload
within main if the datatype is int you call the function as add<int>() etc