473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Value of static variable after object re-created.

rhd
Hi,

- C++ class with a private member function.
- Private member function declares a static int locally with an
initial value of 0 .
- A single instance of the class is created.
- The object calls the member function a number of times, each time
the local variable is incremented.

- Eventually the object calling the member function is deleted.
Static int has a non-zero value at time of deletion.

- A new instance of the class is created.

What will be the value of the static int within the member function
when the object is re-created?
- Will it be 0 or the last value it held before the deletion of the
initial object?

If there were multiple instances of the object would this static
variable, within a non-static member function, be shared between all
instances or would all instances receive their own "static" copy?

Note - Using Microsoft Visual Studio C++ for Windows CE.

rhd

Jul 12 '07 #1
1 1710

rhd
Hi,

- C++ class with a private member function.
- Private member function declares a static int locally with an
initial value of 0 .
- A single instance of the class is created.
- The object calls the member function a number of times, each time
the local variable is incremented.

- Eventually the object calling the member function is deleted.
Static int has a non-zero value at time of deletion.

- A new instance of the class is created.

What will be the value of the static int within the member function
when the object is re-created?
- Will it be 0 or the last value it held before the deletion of the
last value
initial object?

If there were multiple instances of the object would this static
variable, within a non-static member function, be shared between all
instances or would all instances receive their own "static" copy?
shared between all instances
>
Note - Using Microsoft Visual Studio C++ for Windows CE.

rhd
Jul 12 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Richard | last post by:
I have written a static method that uses the Reflection API to scrape all of the names of the instance variables in a class and their corresponding values; and then returns a hashMap containing a...
2
by: Nirvana | last post by:
What's value of uninitialized char declared outside of any function ? cheers
9
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which was written in C by USPS. They don't provide the...
3
by: Helpseeker | last post by:
Hi all, I have written a small code in which i declare a static int variable and increment its value by one each time i click on a button. actually i use the int variable value in a particular URL...
19
by: steve | last post by:
// What I want to do Use enumerated types with the Interlocked.Exchange methods Suggestions please // My estimation of problem Seems like Interlocked.Exchange only works with ints,...
8
by: Simone Chiaretta | last post by:
I've a very strange behaveour related to a website we built: from times to times, something should happen on the server, and all static variables inside the web application, both defined inside aspx...
8
by: hb | last post by:
Hi, I need to declare a variable who's value can be preserve through the same ASP.Net page. I tried the following code, only the static variable s2 keeps its value=22 after lnk1_Click followed...
40
by: Zach | last post by:
Can someone please explain what this means and illustrate the difference with some code. Thanks, Zach
10
by: Brad Baker | last post by:
I have an asp.net/csharp application that requires a particular variable to work properly. This variable is usually passed via a query string in the URL when the application is first run but under...
0
by: zman77 | last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine Hi. This is my first post, though I've "lurked" for a while because I find these forums very helpful....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.