Eigen备忘录
1. 头文件不当会导致编译报错
VSCode 的 clangd (或别的插件?)会悄悄帮忙引入头文件,但也许引入的并符合你的预期:
#include <Eigen/src/Geometry/Transform.h> // 这文件有问题
#include <Eigen/Dense>
#include <Eigen/src/Geometry/Quaternion.h> // 这文件不需要
#include <iostream>
class Vector3
{
public:
float x;
float y;
float z;
Vector3(float x=0, float y=0, float z=0):
x(x), y(y), z(z){}
Vector3(Eigen::Vector3f v):
x(v.x()), y(v.y()), z(v.z()) {} // 此处 v.x(), v.y(), v.z() 会报错
}
改为如下则通过:
#include <Eigen/Dense>
#include <iostream>
class Vector3
{
public:
float x;
float y;
float z;
Vector3(float x=0, float y=0, float z=0):
x(x), y(y), z(z){}
Vector3(Eigen::Vector3f v):
x(v.x()), y(v.y()), z(v.z()) {} // 此处 v.x(), v.y(), v.z() 会报错
}
Greatness is never a given, it must be earned.