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.

Recommended Answers

All 2 Replies

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.

thanks! i'll use that. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.