Re: Is there a "static" in Fortran like in C++?



 DEVELOP > c-Plus-Plus > Re: Is there a "static" in Fortran like in C++?

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1
Topic: DEVELOP > c-Plus-Plus
User: "LR"
Date: 16 Jan 2008 02:03:25 PM
Object: Re: Is there a "static" in Fortran like in C++?
James Giles wrote:

Craig Dedo wrote:

"James Giles" <jamesgiles@worldnet.att.net> wrote in message

...

class element
{
Vector *vsSubdivide;
Matrix *fsSubdivide;
static Vector *SsrSubdivide;
static int maxNumSections;
};

Here, the last two variables are shared by all instances of the
class. If I have two objects of class element, A and B say, then
A.maxNumSections is the *same* thing as B.maxNumSections.

...

Oops. My bad. I did not read the original post closely enough. Thanks
for pointing out this new use of "static".


I should point out (though this is not the place for a C++ tutorial)
that I got the syntax wrong. The way you reference static members
of a class is not through the instances of the class at all. The
way to do is with the class name. So a reference to maxNumSections
would be written as element::maxNumSections. There are other
wierd rules, but as I say this isn't the place. I find this stuff
incredibly confusing and almost always get part of it wrong.

I think you're wrong about that. Both ways seem to work. This code
compiles with VS 2003 and works as expected, and compiles at
http://www.comeaucomputing.com/tryitout/. However, I haven't read the
standard to see what it says, so I might be wrong.
#include <iostream>
class A {
public:
static int b;
};
int A::b = 5;
int main() {
A a;
std::cout << a.b << std::endl;
std::cout << A::b << std::endl;
}
LR
.

 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER