aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/examples
diff options
context:
space:
mode:
authorGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2013-08-02 22:33:12 +0100
committerGravatar Jitse Niesen <jitse@maths.leeds.ac.uk>2013-08-02 22:33:12 +0100
commit8fdffdd573e6d36b04cde595460887dd4e1a2340 (patch)
tree2668361a54e538daaf60c5bc72590f17305547c7 /doc/examples
parent3444f06f684ca10df70b29af812e8f0c572a709a (diff)
Move inheritance from Eigen example in stand-alone file.
Also fix a small mistake (Vector3d instead of VectorXd).
Diffstat (limited to 'doc/examples')
-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;
+}