Question

So I've tried searching here, but haven't quite found the same issue. I can't seem to figure out how to properly use this tracked vector. Ultimately, I want a vector of an array (length == 2) of vectors. It's not that I'm getting an index out of bound message, it's that when I try to compile, it says:

c:\program files (x86)\microsoft visual studio 10.0\vc\include\memory(631): error C2440:     '<function-style-cast>' : cannot convert from 'int' to 'std::vector<_Ty> '
1>          with
1>          [
1>              _Ty=int
1>          ]


//code

int main() {

    typedef vector<int> feature_points[2];
    vector< feature_points >tracked;

    tracked.resize(10);
}

I suppose I could do vector<vector<vector<int>>>, but since the array portion will always be a length of 2, I'd like to just use it as an array of 2, thereby not having to check for index out of bounds exceptions.

Thank you for your thoughts and suggestions.

Was it helpful?

Solution

Use std::array instead of the array For example

#include <array>
#include <vector>

//...
std::vector<std::array<std::vector<int>, 2>> tracked;

Or

#include <array>
#include <vector>

//...
typedef std::array<std::vector<int>, 2> feature_points;
std::vector< feature_points >tracked;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top