Reputation: 5225
I'm trying to compile a -quite large- code base which has some dependencies to Eigen. Doing so, I got the following error: error C2338: THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD
that originates here:
// Eigen\src\Core\DenseCoeffsBase.h
/** \returns a reference to the coefficient at given index.
*
* This method is allowed only for vector expressions, and for matrix expressions having the LinearAccessBit.
*
* \sa operator[](Index) const, operator()(Index,Index), x(), y(), z(), w()
*/
EIGEN_STRONG_INLINE Scalar&
operator[](Index index)
{
#ifndef EIGEN2_SUPPORT
EIGEN_STATIC_ASSERT(Derived::IsVectorAtCompileTime,
THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD)
#endif
eigen_assert(index >= 0 && index < size());
return derived().coeffRef(index);
}
As the Eigen dependencies are all over the code, how can I find the line triggering this error? (obviously, there is a line of code accessing an Eigen matrix using []
, somewhere, this is the line I'm looking for).
Upvotes: 2
Views: 7510
Reputation: 19
Yes, I also encountered similar problem. I defined a matrix as:
Eigen::MatrixXf minor2x2 (2,2)
. When the matrix minor2x2
was initialized like that :
minor2x2[0] = 1.0f;
minor2x2[1] = 1.0f;
minor2x2[2] = 1.0f;
minor2x2[3] = 1.0f;
The same error was triggered. The solution to the problem is to replace minor2x2[i]
to minor2x2(i)
. I think finding Eigen::Matrix
perhaps is helpful.
Upvotes: 1