I use Eigen library in my C++ project and I don't understand how to pass an Eigen::Vector in parameter of my function.
I have in my main function :
Eigen::Vector<double, 3> direction_vector_ned = {1.0, 2.0, 3.0};
Eigen::Vector<double, 3> direction_vector_lla = Reperes::ned_to_lla(direction_vector_ned);
In my Reperes class :
class Reperes
{
private:
public:
static Eigen::Vector<double, 3> ned_to_lla(const Eigen::Vector<double, 3>& ned);
};
And the implementation match with the prototype :
static Eigen::Vector<double, 3> ned_to_lla(const Eigen::Vector<double, 3>& ned)
{
Eigen::Vector<double, 3> lla = {0.0, 0.0, 0.0};
...
return lla;
}
I think the architecture is correct but the compiler raise an error at the call of ned_to_lla() in my main.
I got this error :
undefined reference to `Reperes::ned_to_lla(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&)
I explicitly declared my direction_vector_ned variable
as a Vector<double, 3>
. Why it has been casted into a Matrix<double, 3, 1, 0, 3, 1>
?
I tried to use EigenBase type as mentionned in this section https://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html but it didn't work.
To expand on @Jarod42's comment, you never actually define Reperes::ned_to_lla
. Instead, you define a free function that happens to have the same name as a member function of your Reperes
class. This is NOT an implementation of Reperes::ned_to_lla
:
static Eigen::Vector<double, 3> ned_to_lla(const Eigen::Vector<double, 3>& ned)
{
Eigen::Vector<double, 3> lla = {0.0, 0.0, 0.0};
...
return lla;
}
The above function does not belong to any class.
What you should have written was this:
Eigen::Vector<double, 3> Reperes::ned_to_lla(const Eigen::Vector<double, 3>& ned)
{
Eigen::Vector<double, 3> lla = {0.0, 0.0, 0.0};
...
return lla;
}
Notice the Reperes::
in front of the function name and no keyword static
either (HT @gerum). That's what identifies it as part of your Reperes
class and not some free function.