Call object members into a structure in C++

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I am newish to C++. I am trying to solve a system of equations in C++. These equations contain variables that I store in the class Rectangle. For the solver, I need to define the system of equations as a functor structure. What I need is to pass the variables stored in an class Problem object to the overload operator in struct, where the equations are described. And for the moment I am not able.

This is the definition of my functor:

main.cpp

#include 
#include 
#include    
#include "Functor.h"
#include "Rectangle.h"

using namespace std;

void Rectangle::set_values (int x, int y) {
    width = x;
    height = y;
};

struct my_functor : Functor
{
    my_functor(void):Functor(2,2) {}
    int operator()(const Eigen::VectorXd &x, Eigen::VectorXd &fvect) const
    {
        double a = rect.area();
        cout << a << endl;
        fvect(0) = pow((x(0)-x(1)),2) ;
        fvect(1) = pow((x(0)+15*x(1)+a),2);
        return 0;
    }
};

int main(int argc, char *argv[])
{
    Rectangle rect;
    rect.set_values(2,4);
    rect.area();

    my_functor functor;

    cout << rect.area() << endl;

///solution stuff, irrelevant

    return 0;
}

This is the functor Functor.h


#ifndef TESTSTRUCT_FUNCTOR_H
#define TESTSTRUCT_FUNCTOR_H


//template
template <typename _Scalar, int NX = Eigen::Dynamic, int NY = Eigen::Dynamic >
struct Functor        //: public Time
{


    typedef _Scalar Scalar;

    enum {
        InputsAtCompileTime = NX,
        ValuesAtCompileTime = NY

    };
    typedef Eigen::Matrix<Scalar,InputsAtCompileTime,1
                                                
                                                
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.