diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-03-25 14:17:07 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-03-25 14:17:07 +0100 |
commit | 35f7829af10c61e33dd2e2a7a015058e11a11ea0 (patch) | |
tree | 7135010dcf8fd0a49f3020d52112709bcb883bd6 /eigen/doc/examples/CustomizingEigen_Inheritance.cpp | |
parent | 6e8724193e40a932faf9064b664b529e7301c578 (diff) |
update
Diffstat (limited to 'eigen/doc/examples/CustomizingEigen_Inheritance.cpp')
-rw-r--r-- | eigen/doc/examples/CustomizingEigen_Inheritance.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
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 <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; +} |