473,394 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

using decl, force to file scope only in header file

Possible? Take the following example:

===================
//test1.hpp
namespace B {
typedef int type;
void foo() {}
}
===================
//test.hpp
#include "test1.hpp"

namespace {
using B::type;
using B::foo;
}

namespace A {
void foo(type p) { }
}
#endif
===================
//test.cpp
#include "test.hpp"
int main() {
type a;
A::foo(a);
foo();
}
===================

This compiles (with gnu gcc 4.1.1 at least). I can't seem to figure
out what the standard says about this and why pair can be found even
though its using decl is within an anon namespace.

Given that this doesn't give the desired behavior, is there another
technique that does? (Desired behavior being that type and foo must be
qualified with B:: in test.cpp).

Chris

Sep 26 '07 #1
1 1484
Chris Fairles wrote:
[Q: using declaration forces the file scope only in header?]
Possible?
No, not possible. There is no "file scope". There is only
"translation unit scope". And the translation unit consists of
all the files the compiler has to scan during the processing.
Since you #include the header in your C++ source file, they both
become the translation unit. You cannot declare un-using of the
namespace, so the effect of the 'using' declaration extends to
the _end_ of the translation unit in which it's encountered.
Take the following example:

===================
//test1.hpp
namespace B {
typedef int type;
void foo() {}
}
===================
//test.hpp
#include "test1.hpp"

namespace {
using B::type;
using B::foo;
}

namespace A {
void foo(type p) { }
}
#endif
===================
//test.cpp
#include "test.hpp"
int main() {
type a;
A::foo(a);
foo();
}
===================

This compiles (with gnu gcc 4.1.1 at least). I can't seem to figure
out what the standard says about this and why pair can be found even
though its using decl is within an anon namespace.

Given that this doesn't give the desired behavior, is there another
technique that does? (Desired behavior being that type and foo must be
qualified with B:: in test.cpp).
Yes. Use macros that you can 'define' and 'undef'.
>
Chris
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 26 '07 #2

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

Similar topics

1
by: Inpreet | last post by:
Hello I am using: ************************************************************************* header("Content-Type:application/force-download",false); header("Content-Disposition: attachment;...
6
by: windandwaves | last post by:
Hi Folk Some of my clients asked me to create "fancy emails" for them (aka html formatted emails). I know how to make a nice html document, but I had trouble creating a simple way to provide...
2
by: comp.lang.php | last post by:
class ReportGenerator { function ReportGenerator() {} /** * Generate the HTTP headers necessary for this file type. Can be called statically *
3
by: Bouffa | last post by:
Hello everyone, I suppose you all know force-download scripts. The problem is that these scripts don't allow files to be splitted when downloading them via a download manager. I've found a...
0
by: jinnareddy | last post by:
Hi, I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
5
by: Markus Dehmann | last post by:
I need a Singleton for general program options so that all classes can access it. I use the code below (adapted from the Wikipedia singleton example). But the problem is if I change one variable...
11
by: subramanian100in | last post by:
Suppose the following is in Test.h #ifndef TEST_H #define TEST_H #include <iostream> #include <string> using namespace std;
38
by: Boon | last post by:
Hello group, I've been toying with a simple sudoku solver. I meant for the code to be short and easy to understand. I figured "brute force is simple" -- who needs finesse, when you've got...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.