views:

51

answers:

2

Suppose I defined A::B::int, how can I refer to the standard C++ int inside A::B?

+2  A: 

You cannot have a typedef named int, even if it is in a namespace. int is a keyword.

Keywords are reserved for their specific uses and you cannot use them for any other purpose in your code.

James McNellis
+2  A: 

You can't.

$3.4.2/2-

'If T is a fundamental type, its associated sets of namespaces and classes are both empty.

This means that fundamental types do not have any namespace associated with them.

So you can't even say ::int for this reason.

Chubsdad
Except you can: since you cannot have a typedef named `int`, `int` will always be the fundamental integral type `int`. :-)
James McNellis
What that means is that passing an `int` argument will never pee on your namespace and summon a foreign function from a namespace in a distant land.
Potatoswatter
BTW, you can't say `::int` because such a string can't be formed by the grammar production rules of the standard.
Potatoswatter
Actually, the grammar rules allow it. The grammar production rules for an identifier don't distinguish between `int` and `inT`. The rejection happens (logically) at a different level: after the grammar produces an identifier with a spelling that matches a keyword.
MSalters