H
Hamish
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.
#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.