Topic: static data members access
Author: mahralex@gmx.de ("Alexander Mahr")
Date: Fri, 26 Sep 2003 17:28:39 +0000 (UTC) Raw View
Dear Newsgroup,
As far as I now static data members can be used to share data between
objects of a class
but they are for a reason I don't know why only accesable within the file
they are declared.
In my opinionthis access limitation makes no real sence for it is now
impossible to
use a decleration file like cclass.h within you declare the class and a file
cclass.cpp in
which you write the member functions of the class which of couse shall acces
and change
the static data member?
Can anyone tell me why
static duration comes with a
access limitation?
Regards Alexander
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Mon, 29 Sep 2003 17:00:37 +0000 (UTC) Raw View
In article <bksbap$7de$00$1@news.t-online.com>, Alexander Mahr
<mahralex@gmx.de> writes
>As far as I now static data members can be used to share data between
>objects of a class
>but they are for a reason I don't know why only accesable within the file
>they are declared.
>
>In my opinionthis access limitation makes no real sence for it is now
>impossible to
>use a decleration file like cclass.h within you declare the class and a file
>cclass.cpp in
>which you write the member functions of the class which of couse shall acces
>and change
>the static data member?
>
>Can anyone tell me why
>static duration comes with a
>access limitation?
You posted this question to comp.lang.c++.moderated where you were told
that your question was based on a misunderstanding of the different uses
of static.
Why are you now wasting the time of language experts when programming
ones have already answered your question?
--
Francis Glassborow ACCU
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: wbruna@yahoo.com (Wagner Bruna)
Date: Mon, 29 Sep 2003 17:08:13 +0000 (UTC) Raw View
Hello,
mahralex@gmx.de ("Alexander Mahr") wrote in message news:<bksbap$7de$00$1@news.t-online.com>...
> As far as I now static data members can be used to share data between
> objects of a class
Yes, static _members_; they have class scope, and they _can_ be
acessed from other files.
> but they are for a reason I don't know why only accesable within the file
> they are declared.
These are static _globals_; they have file (actually, translation
unit) scope. Unfortunately, the word "static" has *more* than two
meanings:
http://www.acm.org/crossroads/xrds2-4/ovp.html
++t;
Wagner
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: nikb@webmaster.com ("Nikolaos D. Bougalis")
Date: Mon, 29 Sep 2003 17:08:15 +0000 (UTC) Raw View
""Alexander Mahr"" <mahralex@gmx.de> wrote in message
news:bksbap$7de$00$1@news.t-online.com...
> Dear Newsgroup,
>
> As far as I now static data members can be used to share data between
> objects of a class
> but they are for a reason I don't know why only accesable within the file
> they are declared.
You must be confusing the use of "static" inside a class, to indicate a
variable is to be shared by all instances of a class, and the use of static
ouside the scope of a class or a function.
Accessing a class static member that is public can be done from any
file, provided of course you've imported the declaration of the class
(typically using #include "myclassfile.h")
-n
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kuyper@wizard.net (James Kuyper)
Date: Mon, 29 Sep 2003 17:09:07 +0000 (UTC) Raw View
mahralex@gmx.de ("Alexander Mahr") wrote in message news:<bksbap$7de$00$1@news.t-online.com>...
> Dear Newsgroup,
>
> As far as I now static data members can be used to share data between
> objects of a class
> but they are for a reason I don't know why only accesable within the file
> they are declared.
That is not the case. Could you provide an example of the code whose
failure led you to that conclusion? I suspect that you're facing some
significantly different problem.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: richard_damon@iname.com ("RCN")
Date: Mon, 29 Sep 2003 17:09:26 +0000 (UTC) Raw View
Beware that "static" has several meanings depending on context.
At file scope (outside of a class) static means local to this translation
unit.
At class scope it means not part of any object but effectivly shared by all
objects in the class. Its accessablity will also be possibly limited if it
is in a "private" or "protected" area of the class definition.
Thus:
/* File1 */
static int filestatic =1;
class myclass {
public:
static int classstatic;
};
int myclass::classstatic = 2; // needed to allocate space for static
variable
/* File2 */
static int filestatic; // this is a different variable then in file1
class myclass {
public:
static int classstatic;
};
/*
Here access to myclass::classstatic will get the value from file1
we do not need (and are not allowed) to put the line:
int myclass::classstatic;
as that would lead to a multiple definition of the static variable.
*/
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]