473,805 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.
Jul 19 '05 #1
4 3468
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

Jul 19 '05 #2
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.

Jul 19 '05 #3
In article <bm**********@o rk.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
Jul 19 '05 #4
In article <bm************ *@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
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
29644
by: Joshua Beall | last post by:
Hi All, I remember reading that both nested classes and namespaces would be available in PHP5. I know that namespaces got canceled (much sadness...), however, I *thought* that nested classes were still an option. However, I am coming up dry looking for information on how to do this, and the most recent references I am able to find to nested classes in PHP are dated 2003. And they all say the same thing: sorry, can't do that.
3
1204
by: Rubén Campos | last post by:
Organizing classes, types, structures, enums and whatever other entities into nested namespaces requires to include into every header and implementation file the complete path of namespaces. Let me show an example: classes.hpp classes.cpp util.hpp util.cpp main.cpp // classes.hpp namespace Classes { class MyBaseClass {
11
10996
by: rherring | last post by:
Hello, I have some C++ code that builds against 2 headers files that contain the same function name declaration (gethostname). The header files are not directly included. They are included via other header files. How can I resovle this error? The error (GCC 3.3.2 on Solaris 9): /usr/include/unistd.h:278: error: declaration of C function `int
78
4984
by: Josiah Manson | last post by:
I found that I was repeating the same couple of lines over and over in a function and decided to split those lines into a nested function after copying one too many minor changes all over. The only problem is that my little helper function doesn't work! It claims that a variable doesn't exist. If I move the variable declaration, it finds the variable, but can't change it. Declaring the variable global in the nested function doesn't work...
1
5270
by: maverik | last post by:
Hi all. I have several nested namespaces: A::B::C::MyClass; Can I write in MyClass.h namespace A::B::C { class MyClass {
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.