0

hello guys. :confused:

just a question about vectors: (sorry if it seems stupid, but i really don't know much about vectors)
is it possible to return a vector or a pointer to vector from a function?

if so, how?

thanks in advance.

2
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by potential
0

Yes. To return a vector of strings, for example, you would do this:

vector<string> function();

To return a pointer to a vector of strings, you would do this:

vector<string> *function();

To return a vector of any valid type, you would do something like this:

template <typename T>
vector<T> function();

You can also return a pointer to a vector of any type. Templates are pretty versatile.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.