"2005" <uw*****@yahoo.comwrote:
I have a "private" member "mSize" & "public" function Kite( ).
I want to increment it by 1 everytime it is in the Kite( ).
It appears that the increment disappears as it re-enters Kite( ) the
second time.
So the most I had was mSize =1 (the class initializes to mSize =0).
Is this expected?
Your code does exactly what it you wrote it to do, but it doesn't do
what you want it to do. Therefore, you need to write it to do what you
want, then when it does what you wrote, it will do what you expect.
Is there a way I can do this?
Yes.
I appreciate that you are not simply posting your homework assignment
and asking someone to do it. That really is a good trait. At the same
time, we can't help you if you give us too little information.
Check out the code below, really study it and tell me if it does what
you want done.
class MyClass {
int mSize;
public:
MyClass():mSize(0) { }
int size() const { return mSize; }
void Kite() { ++mSize; }
};
int main() {
MyClass object;
assert( object.size() == 0 );
object.Kite();
assert( object.size() == 1 );
object.Kite();
assert( object.size() == 2 );
}
--
To send me email, put "sheltie" in the subject.