Forward declaration of types MatrixXd & VectorXd?
Asked Answered
G

2

6

Maybe someone knows, is it possible in the Eigen to forward declare types MatrixXd & VectorXd?

While compiling, I get the following error:

/usr/include/eigen3/Eigen/src/Core/Matrix.h:372:34: error: conflicting declaration ‘typedef class Eigen::Matrix Eigen::MatrixXd’

typedef Matrix Matrix##SizeSuffix##TypeSuffix;

SIMP.h

#ifndef SIMP_H
#define SIMP_H


namespace Eigen
{
    class MatrixXd;
    class VectorXd;
}

class SIMP {
public:
    SIMP(Eigen::MatrixXd * gsm, Eigen::VectorXd * displ);
    SIMP ( const SIMP& other ) = delete;
    ~SIMP(){}
    SIMP& operator= ( const SIMP& other ) = delete;
    bool operator== ( const SIMP& other ) = delete;


private:      
    Eigen::MatrixXd * m_gsm;
    Eigen::VectorXd * m_displ;

};

#endif // SIMP_H

SIMP.cpp

#include "SIMP.h"
#include <Eigen/Core>
SIMP::SIMP( Eigen::MatrixXd * gsm, Eigen::VectorXd * displ) :
    m_gsm(gsm),
    m_displ(displ), 
{

}
Goatsucker answered 3/1, 2015 at 21:52 Comment(0)
G
5

No, you cannot "forward declare" type aliases: neither MatrixXd nor VectorXd are classes; they are type aliases.

The best you can do is manually introduce the type aliases early yourself by writing out the typedef statement. This is probably a bad idea.

BTW that last line of output is highly suspicious; it looks like a macro definition, which should definitely not be turning up in a compiler error.

Griffith answered 3/1, 2015 at 22:1 Comment(1)
There some automatic typedefs for setting explicit templates=)Goatsucker
A
3

You can do it like this:

namespace Eigen {
    template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
    class Matrix;
    using MatrixXd = Matrix<double, -1, -1, 0, -1, -1>;
    using VectorXd = Matrix<double, -1, 1, 0, -1, 1>;
}
Abash answered 17/5, 2021 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.