VC++ bug or not?

S

snorkelman

This code works fine with gcc 3.x and 4.0, but generates odd compile
time errors with VC++ 2003 .NET. Is there something subtle that's wrong
with it, or is it just a compiler bug?

struct A {
static const char c = 'A';
};

struct B : public A {
static const char c = 'B';
typedef A PARENT;
};

struct C : public B {
static const char c = 'C';
typedef B PARENT;
};

main()
{
cout << C::c;
cout << C::pARENT::c;
cout << C::pARENT::pARENT::c;
return 0;
}

For some reason, the compiler is unable to resolve the line of code
that attempts to root back through two typedefs to the base class A. It
tells me that "__ctor is not a member of B".
 
J

John Carson

This code works fine with gcc 3.x and 4.0, but generates odd compile
time errors with VC++ 2003 .NET. Is there something subtle that's
wrong with it, or is it just a compiler bug?

struct A {
static const char c = 'A';
};

struct B : public A {
static const char c = 'B';
typedef A PARENT;
};

struct C : public B {
static const char c = 'C';
typedef B PARENT;
};

main()
{
cout << C::c;
cout << C::pARENT::c;
cout << C::pARENT::pARENT::c;
return 0;
}

For some reason, the compiler is unable to resolve the line of code
that attempts to root back through two typedefs to the base class A.
It tells me that "__ctor is not a member of B".

VC++2005 beta 2 compiles and executes the code without a problem. Comeau
also accepts it. Appears to be a bug.
 
V

Victor Bazarov

This code works fine with gcc 3.x and 4.0, but generates odd compile
time errors with VC++ 2003 .NET. Is there something subtle that's wrong
with it, or is it just a compiler bug?

struct A {
static const char c = 'A';
};

struct B : public A {
static const char c = 'B';
typedef A PARENT;
};

struct C : public B {
static const char c = 'C';
typedef B PARENT;
};

main()

Aside from the missing #include and 'using', and the return value type
of the 'main', there is nothing wrong with it.
{
cout << C::c;
cout << C::pARENT::c;
cout << C::pARENT::pARENT::c;
return 0;
}

For some reason, the compiler is unable to resolve the line of code
that attempts to root back through two typedefs to the base class A. It
tells me that "__ctor is not a member of B".

It's a bug. You might want to check with 'microsoft.public.vc.language'
to see if folks who use those compilers the most, know anything about it
or to see how to check if Microsoft knows about it. FWIW, VC++ 2005 Beta
doesn't compile it either.

BTW, all 'c' static consts have to be defined outside the respective class
definitions since they are used elsewhere in the program (in 'main').

V
 
J

John Carson

Victor Bazarov said:
'microsoft.public.vc.language' to see if folks who use those
compilers the most, know anything about it or to see how to check if
Microsoft knows about it. FWIW, VC++ 2005 Beta doesn't compile it
either.

Beta 1? Beta 2 handles it without a problem.
 
S

snorkelman

Thanks all.. If it's fixed in Beta 2 I suspect the chances of any fix
in 2003 .NET are nil. I was mostly concerned that I was up against
personal ignorance of some standard scoping rules and was making a
gaffe.

I'll check the vc newsgroup for vendor-specific info.

|
| Mark Nelson markn at ieee.org
|
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top