[eigen] Ref<> Problem

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Dear all,

If I want to store a Matrix as a reference for read only acces in a class ( I wanted to be able to also reference a Block<> of Matrix, thats why Ref<> )

I wanted to used the Ref<>  class but the following gives some problems:


     struct A{
            A( const         Eigen::Ref< const Eigen::MatrixXd>    &  in)
            : r(in){}

            Eigen::Ref< const Eigen::MatrixXd> r;
     };


      Eigen::MatrixXd a(3,3);    a.setOnes();

       A myA(a.topRows<2>());

      std::cout << myA.r << std::endl; ///< No crash

      A myA2(a.topRows<2>()  *  2);
std::cout << myA.r << std::endl; ///< crash since the expression a.topRows<2>() * 2 was evaluated into a temporary and assigned to a Ref<> in the class




How can I avoid such errors, and whats the correct way of storing a reference to a Matrix in a class?



Thanks a  lot!!

Gabriel



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/