From 35f7829af10c61e33dd2e2a7a015058e11a11ea0 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Mar 2017 14:17:07 +0100 Subject: update --- .../doc/examples/CustomizingEigen_Inheritance.cpp | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 eigen/doc/examples/CustomizingEigen_Inheritance.cpp (limited to 'eigen/doc/examples/CustomizingEigen_Inheritance.cpp') diff --git a/eigen/doc/examples/CustomizingEigen_Inheritance.cpp b/eigen/doc/examples/CustomizingEigen_Inheritance.cpp new file mode 100644 index 0000000..48df64e --- /dev/null +++ b/eigen/doc/examples/CustomizingEigen_Inheritance.cpp @@ -0,0 +1,30 @@ +#include +#include + +class MyVectorType : public Eigen::VectorXd +{ +public: + MyVectorType(void):Eigen::VectorXd() {} + + // This constructor allows you to construct MyVectorType from Eigen expressions + template + MyVectorType(const Eigen::MatrixBase& other) + : Eigen::VectorXd(other) + { } + + // This method allows you to assign Eigen expressions to MyVectorType + template + MyVectorType& operator=(const Eigen::MatrixBase & other) + { + this->Eigen::VectorXd::operator=(other); + return *this; + } +}; + +int main() +{ + MyVectorType v = MyVectorType::Ones(4); + v(2) += 10; + v = 2 * v; + std::cout << v.transpose() << std::endl; +} -- cgit v1.2.3