aboutsummaryrefslogtreecommitdiff
path: root/doc/examples/CustomizingEigen_Inheritance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/CustomizingEigen_Inheritance.cpp')
-rw-r--r--doc/examples/CustomizingEigen_Inheritance.cpp30
1 files changed, 30 insertions, 0 deletions
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 <Eigen/Core>
+#include <iostream>
+
+class MyVectorType : public Eigen::VectorXd
+{
+public:
+ MyVectorType(void):Eigen::VectorXd() {}
+
+ // This constructor allows you to construct MyVectorType from Eigen expressions
+ template<typename OtherDerived>
+ MyVectorType(const Eigen::MatrixBase<OtherDerived>& other)
+ : Eigen::VectorXd(other)
+ { }
+
+ // This method allows you to assign Eigen expressions to MyVectorType
+ template<typename OtherDerived>
+ MyVectorType& operator=(const Eigen::MatrixBase <OtherDerived>& 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;
+}