mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-04 19:20:41 +08:00
doc: Add constructor to example for inheritance.
See "Error in Inheriting Eigen::Vector3d" on forum. (transplanted from b582b2ebdc5657c993698e89db699e885af68c55 )
This commit is contained in:
parent
dee3325ef5
commit
4a7609fa74
@ -83,7 +83,7 @@ An example of when you actually need to inherit Matrix, is when you have
|
|||||||
several layers of heritage such as MyVerySpecificVector1,MyVerySpecificVector1 -> MyVector1 -> Matrix and.
|
several layers of heritage such as MyVerySpecificVector1,MyVerySpecificVector1 -> MyVector1 -> Matrix and.
|
||||||
MyVerySpecificVector3,MyVerySpecificVector4 -> MyVector2 -> Matrix.
|
MyVerySpecificVector3,MyVerySpecificVector4 -> MyVector2 -> Matrix.
|
||||||
|
|
||||||
In order for your object to work within the Eigen framework, you need to
|
In order for your object to work within the %Eigen framework, you need to
|
||||||
define a few members in your inherited class.
|
define a few members in your inherited class.
|
||||||
|
|
||||||
Here is a minimalistic example:\n
|
Here is a minimalistic example:\n
|
||||||
@ -93,8 +93,15 @@ class MyVectorType : public Eigen::VectorXd
|
|||||||
public:
|
public:
|
||||||
MyVectorType(void):Eigen::VectorXd() {}
|
MyVectorType(void):Eigen::VectorXd() {}
|
||||||
|
|
||||||
// You need to define this for your object to work
|
|
||||||
typedef Eigen::VectorXd Base;
|
typedef Eigen::VectorXd Base;
|
||||||
|
|
||||||
|
// This constructor allows you to construct MyVectorType from Eigen expressions
|
||||||
|
template<typename OtherDerived>
|
||||||
|
Vector3D(const Eigen::MatrixBase<OtherDerived>& other)
|
||||||
|
: Eigen::Vector3d(other)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
// This method allows you to assign Eigen expressions to MyVectorType
|
||||||
template<typename OtherDerived>
|
template<typename OtherDerived>
|
||||||
MyVectorType & operator= (const Eigen::MatrixBase <OtherDerived>& other)
|
MyVectorType & operator= (const Eigen::MatrixBase <OtherDerived>& other)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user