static var in a method

G

Gary Wessle

Hi there

I declared a variable static in a member function. it seams to keep
its value between calls for different objects instantiated from the
same type. is this right?
I need it not to do that. only keeps memory between calls for the same
object.

any body can clear this,?

many thanks
 
K

Kai-Uwe Bux

Gary said:
I declared a variable static in a member function. it seams to keep
its value between calls for different objects instantiated from the
same type. is this right?
Yes.

I need it not to do that. only keeps memory between calls for the same
object.

any body can clear this,?

What about making it private member of the class?


Best

Kai-Uwe Bux
 
R

Rolf Magnus

Gary said:
Hi there

I declared a variable static in a member function. it seams to keep
its value between calls for different objects instantiated from the
same type. is this right?
Yes.

I need it not to do that. only keeps memory between calls for the same
object.

Then it should be a non-static member variable instead. That's what member
variables are for: Storing per-object state.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top