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
.