954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help with vectors

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.

potential
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

thanks! i'll use that. :)

potential
Newbie Poster
13 posts since Sep 2004
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You