Static types

C

cpp_weenie

In the class below, what does the keyword "static" do when applied to the
struct? It seems it does *not* make any member variables declared to be of
type "bar" static...

class foo
{
public:
static struct bar
{
int data_1;
int data_2;
};

bar data;
};
 
C

cpp_weenie

In the class below, what does the keyword "static" do when applied to the
struct? It seems it does *not* make any member variables declared to be of
type "bar" static...

class foo
{
public:
static struct bar
{
int data_1;
int data_2;
};

bar data;
};

Let me update my previous post. I think this is a compiler problem (VC++
6.0) - it should not be let through. It doesn't compile under g++ and I
can't find any reference to this type of construct in the Standard.

If it is indeed a compiler problem, sorry to have asked a non-question.
Hope nobody burned too much time on this one...
 
R

Ron Natalie

cpp_weenie said:
In the class below, what does the keyword "static" do when applied to the
struct? It seems it does *not* make any member variables declared to be of
type "bar" static...

class foo
{
public:
static struct bar
{
int data_1;
int data_2;
};

bar data;
};
In this case, absolutey nothing.
If it said:
static struct bar {
int data_1;
int data_2;
} data;

the static applies to data (making it a static member).
 
R

Rob Williscroft

cpp_weenie wrote in
Let me update my previous post. I think this is a compiler problem
(VC++ 6.0) - it should not be let through. It doesn't compile under
g++ and I can't find any reference to this type of construct in the
Standard.

I don't know which is right g++ tells you it doesn't make any sense
and msvc 6.0 just ignores the static. It may well be that this is
implementation defined behaviour, so both could be conforming.
If it is indeed a compiler problem, sorry to have asked a
non-question. Hope nobody burned too much time on this one...

Perhapse this will help it all make sense note the 'variable'
identifiyer:

#include <iostream>

class foo
{
public:
static struct bar
{
int data_1;
int data_2;
} variable;

bar data;
};

foo::bar foo::variable = { 10, 12 };

int main()
{
std::cerr << foo::variable.data_1 << "\n";
}

Rob.
 
R

Ron Natalie

Rob Williscroft said:
I don't know which is right g++ tells you it doesn't make any sense
and msvc 6.0 just ignores the static. It may well be that this is
implementation defined behaviour, so both could be conforming.

It's not conforming. If you place a storage class specifier (such
as static), then you have to go ahead and declare a variable.
Standard section 7.1.1. Says so in the third sentence of that section.
 
C

cpp_weenie

It's not conforming. If you place a storage class specifier (such
as static), then you have to go ahead and declare a variable.
Standard section 7.1.1. Says so in the third sentence of that section.

As an additional note, I just tried it under VC++ 7.1 as well. I found that
it let this non-conforming construct through without so much as a warning!

Bill did pretty good this time around, but I have found several little
things like this...
 
J

Josephine Schafer

cpp_weenie said:
As an additional note, I just tried it under VC++ 7.1 as well. I found that
it let this non-conforming construct through without so much as a warning!
Yep..VC++ 7 doesn't crib even with /Za (disable language extensions).
Many times compilers differ in their behavior on the same code.
IMO, one should compile code (standard C++) on atleast two compilers.
Referring to the standard definitely tells which compiler is correct but may
times the interpretation is left to the reader.
In such cases I personally trust Comeau's implementation. Nice to see a compiler
which can claim to be almost standard compliant.
( I read somewhere that Comeau has some problems with Koenig lookup)

HTH,
J.Schafer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top