473,327 Members | 1,997 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,327 software developers and data experts.

For classes with static members

Can a class with out any instances present have it static members
updated.

If yes, on which object does the update happen.
-Parag
Dec 18 '07 #1
5 1471
On 2007-12-18 15:00:56 -0500, "pa********@hotmail.com"
<pa********@hotmail.comsaid:
Can a class with out any instances present have it static members
updated.
Yes.
>
If yes, on which object does the update happen.
None. Static member variables belong to the class, not to any object.

--

-kira

Dec 18 '07 #2
On Dec 19, 1:00 am, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
Can a class with out any instances present have it static members
updated.

If yes, on which object does the update happen.
-Parag
But yes one needs to make sure that they are initialized once before
any usage.
The initialization makes sure that the memory is allocated for the
static member variables.
Any usage of static member variables without initialization could
cause unresolved external symbol linker error...
Dec 19 '07 #3
On Dec 19, 4:45 am, Rahul <sam_...@yahoo.co.inwrote:
On Dec 19, 1:00 am, "parag_p...@hotmail.com"
<parag_p...@hotmail.comwrote:
Can a class with out any instances present have it static
members updated.
If yes, on which object does the update happen.
But yes one needs to make sure that they are initialized once
before any usage.
That's true for most variables, but not for static POD types,
which are automatically zero initialized before any code is run.
The initialization makes sure that the memory is allocated for
the static member variables.
The initialization of a static variable has nothing to do with
memory allocation.
Any usage of static member variables without initialization
could cause unresolved external symbol linker error...
You'll likely get an unresolved external symbol error from the
linker if you fail to define the symbol, but the linker doesn't
care in the least about initialization.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Dec 19 '07 #4
On Dec 19, 3:00 pm, James Kanze <james.ka...@gmail.comwrote:
On Dec 19, 4:45 am, Rahul <sam_...@yahoo.co.inwrote:
On Dec 19, 1:00 am, "parag_p...@hotmail.com"
<parag_p...@hotmail.comwrote:
Can a class with out any instances present have it static
members updated.
If yes, on which object does the update happen.
But yes one needs to make sure that they are initialized once
before any usage.

That's true for most variables, but not for static POD types,
which are automatically zero initialized before any code is run.
The initialization makes sure that the memory is allocated for
the static member variables.

The initialization of a static variable has nothing to do with
memory allocation.

What is the initialization meant for?
>
Any usage of static member variables without initialization
could cause unresolved external symbol linker error...

You'll likely get an unresolved external symbol error from the
linker if you fail to define the symbol, but the linker doesn't
care in the least about initialization.

--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 19 '07 #5
Rahul wrote:
On Dec 19, 3:00 pm, James Kanze <james.ka...@gmail.comwrote:
>On Dec 19, 4:45 am, Rahul <sam_...@yahoo.co.inwrote:
>>On Dec 19, 1:00 am, "parag_p...@hotmail.com"
<parag_p...@hotmail.comwrote:
Can a class with out any instances present have it static
members updated.
If yes, on which object does the update happen.
But yes one needs to make sure that they are initialized once
before any usage.
That's true for most variables, but not for static POD types,
which are automatically zero initialized before any code is run.
>>The initialization makes sure that the memory is allocated for
the static member variables.
The initialization of a static variable has nothing to do with
memory allocation.


What is the initialization meant for?
To initialise the state of the variable, just like any other. Leaving a
static member uninitialised doesn't mean it's not there.

--
Ian Collins.
Dec 19 '07 #6

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

Similar topics

3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
11
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you...
4
by: JC | last post by:
Suppose an ASP.Net project contains a public static class with public methods and members that are used throughout the application. Of course being static, there is only copy of the class within...
16
by: chameleon | last post by:
I have 2 classes with exactly the same members (all static except dtor/ctor). Classes have different implementantion in only one static member function and first class has one more member...
3
by: puzzlecracker | last post by:
Would you quickly remind me the difference between, regular class, static class, and nested class? Thanks
5
by: Andy B | last post by:
I have a class that I want to make static but it uses some objects that are instance objects. I keep getting a compiler error saying something about using instance objects in a static class or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.