In my code, I have some data stored in an 2d array of vector and I'd like to use it in another class to process the data but I can't find a way to do that.
Here is a sample of what I tried:
vector<IndividualData> vecArray[5][5]; // The one I want to pass to the class
MyClass::MyClass(vector<IndividualData> data[][5], ...):_data(data)
Is there a good way to do that?
I also tried with the std::array but I can't make it work:
array<array<vector<IndividualData>, 5>, 5> testVec; // Ther one I want to pass to the class
MyClass::MyClass(array<array<vector<IndividualData>, 5>, 5>& data, ...): _data(data)
When I want to use it in the class, I get the following error:
Type 'array<array<vector, 5>, 5>' does not provide a subscript operator
With
printf("%d\r\n", _data[0][0][0].param);
and
array<array<vector<IndividualData>, 5>, 5>& _data;
Thank's in advance for your replies
This works for me:
using My2DArrayOfVec = std::array<std::array<std::vector<IndividualData>, 5>, 5>;
class MyClass
{
My2DArrayOfVec _data;
public:
MyClass(My2DArrayOfVec const& data, ...) : _data(data) {}
void useIt() const { printf("%d\r\n", _data[0][0][0].param); }
};
By having an alias, I always use the same types, My2DArrayOfVec
, inside and outside of my class even when I'm experimenting.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.