From 8fdffdd573e6d36b04cde595460887dd4e1a2340 Mon Sep 17 00:00:00 2001 From: Jitse Niesen Date: Fri, 2 Aug 2013 22:33:12 +0100 Subject: Move inheritance from Eigen example in stand-alone file. Also fix a small mistake (Vector3d instead of VectorXd). --- doc/examples/CustomizingEigen_Inheritance.cpp | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 doc/examples/CustomizingEigen_Inheritance.cpp (limited to 'doc/examples') diff --git a/doc/examples/CustomizingEigen_Inheritance.cpp b/doc/examples/CustomizingEigen_Inheritance.cpp new file mode 100644 index 000000000..48df64ee3 --- /dev/null +++ b/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