leading_attention
leading_attention

Reputation: 1

How to convert const Eigen::VectorXcf to Eigen::VectorXcf?

I want to convert the pointer to const VectorXcf to VectorXcf in eigen library. I tried const_cast<VectorXcf> but it did not work. Following is the error log:

error: invalid conversion from 'const Vector2cf* {aka const
Eigen::Matrix<std::complex<float>, 2, 1>*}' to 'Eigen::Vector2cf* {aka
Eigen::Matrix<std::complex<float>, 2, 1>*}' [-fpermissive]

Upvotes: 0

Views: 212

Answers (1)

Avi Ginsburg
Avi Ginsburg

Reputation: 10596

Can you please show exactly what didn't work for you? I have MCVE taht works both in Visual Studio 2015 and gcc 6.3.0 (mingw) compiled with -Wall:

#include <iostream>
#include <Eigen/Core>

using namespace Eigen;

int main()
{
    typedef VectorXcf T;

    T mat(10);

    const T& matConstRef = mat;
    T* nc = const_cast<T*>(&matConstRef);
    nc->setConstant(T::Scalar(3.4));
    std::cout << *nc << "\n\n";
    Map<T> map = Map<T>(const_cast<T::Scalar*>(matConstRef.data()), matConstRef.rows(), matConstRef.cols());
    map << 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
    std::cout << map << "\n\n";
    return 0;
}

It compiles without any warnings and gives the expected result.

Upvotes: 2

Related Questions