1
*error: no matching function for call to object of type 'Eigen::VectorXd' (aka 'Matrix<double, Dynamic, 1>')
DenseCoeffsBase.h:362:5: note: candidate function not viable: no known conversion from 'double *' to 'Eigen::Index' (aka 'long long') for 1st argument; dereference the argument with *
DenseCoeffsBase.h:115:41: note: candidate function not viable: no known conversion from 'double *' to 'Eigen::Index' (aka 'long long') for 1st argument; dereference the argument with *
DenseCoeffsBase.h:178:5: note: candidate function not viable: requires single argument 'index', but 2 arguments were provided
DenseCoeffsBase.h:423:5: note: candidate function not viable: requires single argument 'index', but 2 arguments were provided*

The above was the error message provided when I try to store the data from a standard vector to a Eigen Vector

Here's what I'm trying to do. I've made std vectors in other files that I'm returning through those commands and then have to convert them to eigen style vectors to integrate with some other code.I have tried looking for ways to store std vector data into eigen and I found this particular way on another stack overflow post. I dont understand what the error messsage means. Can someone tell me what I'm doing wrong?

Also in an effort to print out the data, I get this error "Reference to non static member function must be called:did you mean to call it with no arguments"

I thought I made it a static vector by resizing.

I'd appreciate help and will add any information necessary. I'm kind of new to C++, and would appreciate a bit simpler explanations as I'm not well versed with all the fundamentals.

    simulator.h

    Eigen::VectorXd currentStartMassVector_, currentEndMassVector_ ,specificImpulses_   ;
    std::vector<double>       StartMassVector_, endMassVector_ , SpecificImpulseVector_  ;

    simulator.cpp

    currentStartMassVector_.resize(numberOfStages_);
    currentEndMassVector_.resize(numberOfStages_);
    specificImpulses_.resize(numberOfStages_);

    StartMassVector_            = launchVehicle->getMassStartStages();
    endMassVector_              = launchVehicle->getMassEndStages();
    SpecificImpulseVector_      = launchVehicle->getCurrentSpecificImpulse();

    currentStartMassVector_(StartMassVector_.data(),StartMassVector_.size())  ;
    currentEndMassVector_(endMassVector_.data(),endMassVector_.size()) ;
    specificImpulses_(SpecificImpulseVector_.data(),SpecificImpulseVector_.size());

        std::cout << "start mass vector" <<  currentStartMassVector_.transpose << std::endl;
        std::cout << "end mass vector"   <<  currentEndMassVector_.transpose << std::endl;
        std::cout << "Isp vector" <<  specificImpulses_.transpose << std::endl;
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Rajath Pai
  • 145
  • 7
  • What function of `Eigen::VectorXd` (aka `Eigen::Matrix`) do you expect to provide such a conversion? Note that you are invoking a _function-call operator_ here: `currentStartMassVector_(StartMassVector_.data(),StartMassVector_.size());`. Does it even exist? – Daniel Langr Jan 03 '20 at 08:59
  • https://stackoverflow.com/questions/17036818/initialise-eigenvector-with-stdvector This is where I got my conversion function (or lack there of) from @DanielsaysreinstateMonica and yes you are pointing to the source of my info. Am i using it right? This is what created my errors. – Rajath Pai Jan 03 '20 at 09:05
  • The problem is that the answers in that question pass arguments to a _constructor_, but you to a _function-call operator_. `currentStartMassVector_(...);` is the same as `currentStartMassVector_.operator()(...);`. You should also check the answers that use `Eigen::Map`. – Daniel Langr Jan 03 '20 at 09:09

1 Answers1

3

You can only use the constructor to initialize a vector that was not previously declared. In this case, the Eigen vectors are already declared in the header file.

Eigen::Map() can be used to copy the data from the std::vector<double> to the Eigen::VectorXd, like this:

currentStartMassVector_ = Eigen::Map<Eigen::VectorXd>(StartMassVector_.data(),StartMassVector_.size()) ;
RHertel
  • 23,412
  • 5
  • 38
  • 64