Returning an Array of Vectors ?

mr_mongo
mr_mongo used Ask the Experts™
on
I have some Data which i want to return from a function. There are int, boolean and string values, which form a set, like a row. My idea was as follows:

vector** my_func()
{
vector data[3];
data[0] = new vector<string>;
data[1] = new vector<int>;
data[2] = new vector<bool>;
[....]
return data;
}

Now i cannot specify the data type of the template class, because the array contains different types of vectors. Is this already the answer why it is not possible, or is there a way to achive the functionality I intend?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2012
Commented:
>>is there a way to achive the functionality I intend?

struct vector_container {

 vector<string>* pStringVec;
 vector<int>* pIntVec;
 vector<bool>* pBoolVec;
}

vector_container my_func()
{
vector_container data;
data.pStringVec = new vector<string>;
data.pIntVec = new vector<int>;
data.pBoolVect = new vector<bool>;
[....]
return data;
}

Author

Commented:
ok, nice workaround - could have thought of it myself.
remains the (more theoretical) question if ther is such thing as "array of vectors"
jkr
Top Expert 2012

Commented:
>>remains the (more theoretical) question if ther is such thing as "array of vectors"

There is certainly something as a 'vector of vectors of the same type'. You cannot create a vector of vectors of mixed typed without giving up type-safety (e.g. storing void* to vectors)
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Commented:
You can *indirectly* create a vector of vectors of mix types, but you have to use a Heterogenous class.

Author

Commented:
presented a practicable workaround, although not completely covering the question at first. But the very quick response made totally up for this.
EOL

Commented:
look at the boost pages for a practicable solution to the problem of containers containing different datatypes (Anythings). Also consider the idea of containers that hold base shared_ptr that are manufactured via allocators and retireved via checkin casters.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial