Frank
2014-02-11 15:10:10 UTC
Dear people,
could someone please help me here? I made a two-dimensional
array, i. e. a vector of vectors, templated:
----- SNIP -----
template< typename VEC2_ELEMENT // element type
class vec2 : public std::vector <std::vector<VEC2_ELEMENT> >
{
public:
// something here
// longest returns the # of elements of the sub-vector with the most elements
int longest()
{
if (size() > 0)
{
// longestindex returns the index of the sub-vector with the most elements
return this->at(longestindex()).size(); // works
// return this[longestindex()].size(); // doesn't work
}
else
return -1;
}
} ;
----- SNIP -----
Now why is it that the "at" statement works but the "[]²
statement returns the # of lines, i. e. the # of sub-vectors?
Example: The whole vec2 contains 3 sub-vectors with
5, 8, and 2 elements. The "works" version returns 8,
the "doesn't work" version returns 3.
could someone please help me here? I made a two-dimensional
array, i. e. a vector of vectors, templated:
----- SNIP -----
template< typename VEC2_ELEMENT // element type
class vec2 : public std::vector <std::vector<VEC2_ELEMENT> >
{
public:
// something here
// longest returns the # of elements of the sub-vector with the most elements
int longest()
{
if (size() > 0)
{
// longestindex returns the index of the sub-vector with the most elements
return this->at(longestindex()).size(); // works
// return this[longestindex()].size(); // doesn't work
}
else
return -1;
}
} ;
----- SNIP -----
Now why is it that the "at" statement works but the "[]²
statement returns the # of lines, i. e. the # of sub-vectors?
Example: The whole vec2 contains 3 sub-vectors with
5, 8, and 2 elements. The "works" version returns 8,
the "doesn't work" version returns 3.