Incrementing using ....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 2005

    #1

    Incrementing using ....

    Hi

    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?

    Is there a way I can do this?

    Thank you

  • Gavin Deane

    #2
    Re: Incrementing using ....


    2005 wrote:
    Hi
    >
    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?
    Not by you, it would seem. Nobody else has any expectations one way or
    the other since nobody else can see your code.
    Is there a way I can do this?
    I expect so.

    The FAQ tells you how to post questions about problem code.


    Follow *all* those guidelines and you will get the help you want.

    Gavin Deane

    Comment

    • Julián Albo

      #3
      Re: Incrementing using ....

      2005 wrote:
      It appears that the increment disappears as it re-enters Kite( ) the
      second time.
      Yes, it disappeared. I can't see it.

      --
      Salu2

      Comment

      • Salt_Peter

        #4
        Re: Incrementing using ....


        2005 wrote:
        Hi
        >
        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?
        >
        Thank you
        Thats, nice. Share the code or a reconstruction that is compileable.
        Otherwise, you are out of luck.

        Comment

        • JonathanK.Kelly@gmail.com

          #5
          Re: Incrementing using ....

          What you could do is make the mSize variable static so that only one
          instance of it is created. Inside of the function Kite increment the
          value of mSize, this way multiple objects of your class will share the
          same mSize variable.

          On Oct 26, 5:34 pm, "Salt_Peter " <pj_h...@yahoo. comwrote:
          2005 wrote:
          Hi
          >
          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?
          >
          Thank youThats, nice. Share the code or a reconstruction that is compileable.
          Otherwise, you are out of luck.

          Comment

          • Daniel T.

            #6
            Re: Incrementing using ....

            "2005" <uws2003@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.

            Comment

            • Salt_Peter

              #7
              Re: Incrementing using ....

              [please don't top post] reorganized...
              >
              On Oct 26, 5:34 pm, "Salt_Peter " <pj_h...@yahoo. comwrote:
              2005 wrote:
              Hi
              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?
              Thank youThats, nice. Share the code or a reconstruction that is compileable.
              Otherwise, you are out of luck.
              JonathanK.Kelly @gmail.com wrote:
              What you could do is make the mSize variable static so that only one
              instance of it is created. Inside of the function Kite increment the
              value of mSize, this way multiple objects of your class will share the
              same mSize variable.
              Thats not neccessarily the right strategy since then *all* the objects
              have the same static "mSize". We have no knowledge about what Kite() or
              mSize are attempting to solve since we can't see the problem.

              Comment

              Working...