Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Incrementing using ....

Reply
Thread Tools

Incrementing using ....

 
 
2005
Guest
Posts: n/a
 
      10-26-2006
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

 
Reply With Quote
 
 
 
 
Gavin Deane
Guest
Posts: n/a
 
      10-26-2006

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.
http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

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

Gavin Deane

 
Reply With Quote
 
 
 
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      10-26-2006
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
 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      10-26-2006

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.

 
Reply With Quote
 
JonathanK.Kelly@gmail.com
Guest
Posts: n/a
 
      10-26-2006
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.com> wrote:
> 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.


 
Reply With Quote
 
Daniel T.
Guest
Posts: n/a
 
      10-27-2006
"2005" <> wrote:

> 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.
 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      10-27-2006
[please don't top post] reorganized...
>
> On Oct 26, 5:34 pm, "Salt_Peter" <pj_h...@yahoo.com> wrote:
> > 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.


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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Incrementing value test Salman VHDL 2 04-13-2005 04:52 PM
Incrementing Assembly Version? =?Utf-8?B?bWVraW0=?= ASP .Net 5 10-29-2004 01:08 PM
Incrementing VHDL FOR loop constant by a value other than 1 Josh Graham VHDL 3 04-07-2004 07:03 AM
looping/incrementing problem... Mothra Perl 3 12-10-2003 02:01 AM
Incrementing Datagrid Value -- Simple Question Ron ASP .Net 0 06-30-2003 04:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57