CustomizingEigen_Inheritance.cpp
Go to the documentation of this file.
1 #include <Eigen/Core>
2 #include <iostream>
3 
4 class MyVectorType : public Eigen::VectorXd
5 {
6 public:
7  MyVectorType(void):Eigen::VectorXd() {}
8 
9  // This constructor allows you to construct MyVectorType from Eigen expressions
10  template<typename OtherDerived>
11  MyVectorType(const Eigen::MatrixBase<OtherDerived>& other)
12  : Eigen::VectorXd(other)
13  { }
14 
15  // This method allows you to assign Eigen expressions to MyVectorType
16  template<typename OtherDerived>
17  MyVectorType& operator=(const Eigen::MatrixBase <OtherDerived>& other)
18  {
19  this->Eigen::VectorXd::operator=(other);
20  return *this;
21  }
22 };
23 
24 int main()
25 {
26  MyVectorType v = MyVectorType::Ones(4);
27  v(2) += 10;
28  v = 2 * v;
29  std::cout << v.transpose() << std::endl;
30 }
Array< int, Dynamic, 1 > v
Base class for all dense matrices, vectors, and expressions.
Definition: MatrixBase.h:52
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:182
Matrix & operator=(const Matrix &other)
Assigns matrices to each other.
Definition: Matrix.h:208
Matrix< double, Dynamic, 1 > VectorXd
DynamicĂ—1 vector of type double.
Definition: Matrix.h:502
: InteropHeaders
Definition: Core:139