| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Hamish" |
| Date: |
16 Oct 2003 04:09:12 AM |
| Object: |
Conflicts with Nested Namespaces |
Consider the following code:
#include <iostream>
typedef int Thingo;
namespace A
{
namespace B
{
void
Thingo();
}
}
void
A::B::Thingo()
{
std::cout << "Reached: void A::B::Thingo()" << std::endl;
}
int
main()
{
A::B::Thingo();
return 0;
}
This code generates the following error on g++ versions 3.2.2 and
2.96:
$ g++ test.cc
test.cc: In function `void A::B::Thingo()':
test.cc:16: `void A::B::Thingo()' redeclared as different kind of symbol
test.cc:3: previous declaration of `typedef int Thingo'
The error goes away if:
- you wrap the typedef in an anonymous namespace;
- you use 'struct B' instead of 'namespace B'; or
- you include the definition of void A::B::Thingo() either
namespace A or B.
- you replace the typedef with struct Thingo {};
The error remains if:
- you replace the typedef with enum { Thingo };
Could someone please explain what is wrong with the code. For the life
of me I can't figure out why it's unacceptable.
Thanks in advance,
Hamish.
.
|
|
| User: "stephan beal" |
|
| Title: Re: Conflicts with Nested Namespaces |
16 Oct 2003 06:30:32 AM |
|
|
Hamish wrote:
Consider the following code:
typedef int Thingo;
namespace A
{
namespace B
{
void
Thingo();
}
}
This code generates the following error on g++ versions 3.2.2 and
2.96:
$ g++ test.cc
test.cc: In function `void A::B::Thingo()':
test.cc:16: `void A::B::Thingo()' redeclared as different kind of symbol
test.cc:3: previous declaration of `typedef int Thingo'
i've seen similar errors from gcc 3.3pre, but i don't have a solution.
Regaring 2.96: ONLY RedHat released that version - GNU never did, so it is
not to be trusted, IMO. If you'll look on ftp.gnu.org you'll not find a
copy of 2.96.
--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.
.
|
|
|
| User: "Hamish Ivey-Law" |
|
| Title: Re: Conflicts with Nested Namespaces |
16 Oct 2003 08:05:25 AM |
|
|
In article <bmlv7o$bkr$1@ork.noris.net>, stephan beal wrote:
Regaring 2.96: ONLY RedHat released that version - GNU never did, so it is
not to be trusted, IMO. If you'll look on ftp.gnu.org you'll not find a
copy of 2.96.
I'm well aware of that; I'm lead to believe that RedHat included gcc 2.96
(the internal gcc developers' codename for the upcoming 3.x series) in their
7.2 release because they needed a compiler that supported the ia64 chips.
The only reason I've used that compiler at all is because I was forced to
do some development on that acursed 7.2 platform. Nothing worked properly.
--
Hamish
.
|
|
|
|
|
| User: "Rolf Magnus" |
|
| Title: Re: Conflicts with Nested Namespaces |
16 Oct 2003 04:33:51 AM |
|
|
Hamish wrote:
Could someone please explain what is wrong with the code. For the
life of me I can't figure out why it's unacceptable.
I don't see why there should a conflict, and comeau online compiles it
without errors, so I suspect a bug in g++ 3.2.2
.
|
|
|
| User: "Hamish" |
|
| Title: Re: Conflicts with Nested Namespaces |
16 Oct 2003 08:08:06 AM |
|
|
In article <bmloqg$6tc$07$1@news.t-online.com>, Rolf Magnus wrote:
Hamish wrote:
Could someone please explain what is wrong with the code. For the
life of me I can't figure out why it's unacceptable.
I don't see why there should a conflict, and comeau online compiles it
without errors, so I suspect a bug in g++ 3.2.2
I was fearing that. It didn't come up in my searches of the gcc bug
archives either.
--
Hamish
.
|
|
|
|
|

|
Related Articles |
|
|