Singleton version gives different values....

Hi,

I've written a class with a simple inline function to return a member variable (a byte)....

    inline byte getKpFixInt(){return _fixIntKp;}

The class compiles fine and has passed all my testing with flying colours. Then I wrote a singleton version of this class. the header for the singleton version includes this prototype...

    byte getKpFixInt();

And the .cpp file includes this entry for the function...

byte sCompressFix::getKpFixInt()
{
  comp1.getKpFixInt();
}

So, there's no rocket science here, it's all pretty simple. I then ran the singleton version of the class through all the same tests, again everything works ok, and I get all the same results as I did for the non-singleton version, EXCEPT for the single function listed above.

My first thought was that maybe _fixIntKp was getting corrupted by the complexities of the code within the class. However I tried hardcoding it's value in the constructor of the original class like this.....

/**************************************************************************
  Constructor
**************************************************************************/
CompressFix::CompressFix()
{
  _fixIntKp = 230;
}

And then calling getKpFixInt() before any other functions but the result is always the same. If I use the non-singleton version of the class I get the correct value (230) but if I use the singleton version I get 247.

Any ideas?

I'm running this on a Mega, and I've written successful singleton versions of classes so I think I've got the syntax correct (also, remember that all the other functions of the singleton version of the class seem to be working fine.)

What I'm finding really puzzling is how anything can go wrong with something simple, step one, I set a value, step 2 I read a value, but somehow the value changes?

Aren't you missing "return"?

Sorry to be blunt, but...
You are showing bits of nothing from some class called 'sCompressFix' and 'CompressFix', we need real code to do more than guess.

byte sCompressFix::getKpFixInt()
{
  comp1.getKpFixInt();
}

Seems pretty clear to me.

shouldn't that be a compile error rather than a wrong number?

You are showing bits of nothing

That's kinda the point, the class wasn't doing anything! I'd striped out all the code that actually did anything, and was still getting the wrong value.

Aren't you missing "return"?

Seems pretty clear to me.

Okay, okay I admit it, I'm a 1di0t. Yup that was the problem, all sorted now. To be honest, I'd kinda half spotted it myself, but I'd looked at my other singleton functions and they didn't have 'returns' and yet somehow (random luck???) returned what appeared to be the correct values.

shouldn't that be a compile error rather than a wrong number?

I'd have thought so too, but having demonstrated that I'm an idiot, I'll just shut up now!

Thanks for your help.