#include USING_PART_OF_NAMESPACE_EIGEN using namespace std; template Eigen::Row firstRow(MatrixBase& m) { return Eigen::Row(m.ref(), 0); } template const Eigen::Row firstRow(const MatrixBase& m) { return Eigen::Row(m.ref(), 0); } int main(int, char**) { Matrix4d m = Matrix4d::identity(); cout << firstRow(2*m) << endl; // calls the const version firstRow(m) *= 5; // calls the non-const version cout << "Now the matrix m is:" << endl << m << endl; return 0; }