class member initialize/return problem

Hi it's my first time posting on the forums. But anyways I'm having a problem with one of my functions inside my class. It's return the wrong value and I have no clue why. For example if I set the variable to 0 and I use the function to inc it by one it goes to either 1 or 2. I've had both results. Now if I loop printing it to the screen in my main it increases by 2 instead of 1.

Example code:
1
2
3
4
5
6
7
8
//abc.h
Class abc
{
private:
int x;
public:
  int SetX();
};


1
2
3
4
5
6
7
8
9
10
//abc.cpp
abc::abc()
{
   abc::x = 0;
}

int abc::setX()
{
   return abc::SetX++;
}


That is just an example of what my code is as I'm not home currently to type it code for code. I'm assuming that it's something in my abc.cpp example.But in the main all it does is a simple cout to display the return so I.doubt it's that. Thankyou in advance for the help! Oh and also I'm on my phone so sorry about not tabbing my code I had to use spaces :P
You are returning a function not a variable, look closely

and when you access a member variable inside a member function you don't need scope operator :: it is only needed when defining a member function outside the class:

1
2
3
4
abc::abc
{
    x = 0;
}
Thankyou so much. I'm still learning all the stuff with classes so I.wasn't really sure how I'd define x. But again thankyou
Topic archived. No new replies allowed.