mercredi 23 mars 2022

GDB not updating variable

I am working on a c++ code for solving fluid dynamics problems,

I am changing a templated class to store two static variables. I am also creating two separate functions to change the corresponding value:

static int sizeOfTensor;
static void setSize(const int& newSize);

static int hOp;
static void sethOp(const int& newSize);

And their corresponding implementation:

template <class Cmpt, int length>
int  myTensor<Cmpt, length>::sizeOfTensor = length;

template <class Cmpt, int length>
void myTensor<Cmpt, length>::setSize(const int& newSize)
{
sizeOfTensor = newSize;
}

template <class Cmpt, int length>
int  myTensor<Cmpt, length>::hOp = length;

template <class Cmpt, int length>
void myTensor<Cmpt, length>::sethOp(const int& newSize)
{
    hOp = newSize;
}

When I execute these functions in the code:

myTensor<double,4> a;

myTensor<double,4>::sethOp(2);

myTensor<double,4>::setSize(3);

std::cout << myTensor<double,4>::hOp << std::endl;

In gdb the variable sizeOfTensor will change its value but the hOp won't. However, if I ask to print the value it is the correct one.

Why is this happening?!

Best Regards

Aucun commentaire:

Enregistrer un commentaire