- #1
CAF123
Gold Member
- 2,948
- 88
Hi all, simple question but I cannot understand what is going wrong. I have a CLASS.hpp file of the form
and then in the CLASS.cpp file I have a call to this function func() via:
The code compiles and runs fine, the problem is when I replace varA with 5. in the double func, the output is different than if I do as above. Of course my code is more complicated but I have checked that when I replace varA with 5 rather than fetching the value from the header file, the output changes. Is there something wrong in the above? Thanks!
Code:
class CLASS
{
private:
double varA = 5.; //some numerical value
public:
double func(double z);
};
and then in the CLASS.cpp file I have a call to this function func() via:
Code:
#include "CLASS.hpp"
double CLASS::func(double z) {
double var = varA; //or this->varA should work too
double result = var*var; //some function of var
return result;
};
The code compiles and runs fine, the problem is when I replace varA with 5. in the double func, the output is different than if I do as above. Of course my code is more complicated but I have checked that when I replace varA with 5 rather than fetching the value from the header file, the output changes. Is there something wrong in the above? Thanks!
Last edited by a moderator: