Suppose I defined A::B::int
, how can I refer to the standard C++ int
inside A::B
?
views:
51answers:
2
+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
2010-08-29 05:44:05
+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
2010-08-29 05:45:42
Except you can: since you cannot have a typedef named `int`, `int` will always be the fundamental integral type `int`. :-)
James McNellis
2010-08-29 05:52:49
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
2010-08-29 06:06:31
BTW, you can't say `::int` because such a string can't be formed by the grammar production rules of the standard.
Potatoswatter
2010-08-29 06:09:53
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
2010-08-30 11:21:58