Link to home
Start Free TrialLog in
Avatar of mr_mongo
mr_mongo

asked on

Returning an Array of Vectors ?

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?
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mr_mongo
mr_mongo

ASKER

ok, nice workaround - could have thought of it myself.
remains the (more theoretical) question if ther is such thing as "array of vectors"
>>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)
You can *indirectly* create a vector of vectors of mix types, but you have to use a Heterogenous class.
presented a practicable workaround, although not completely covering the question at first. But the very quick response made totally up for this.
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.