How to access hidden template in unnamed namespace?
Posted
by Johannes Schaub - litb
on Stack Overflow
See other posts from Stack Overflow
or by Johannes Schaub - litb
Published on 2010-05-28T21:29:28Z
Indexed on
2010/05/28
21:32 UTC
Read the original article
Hit count: 292
Here is a tricky situation, and i wonder what ways there are to solve it
namespace {
template <class T>
struct Template { /* ... */ };
}
typedef Template<int> Template;
Sadly, the Template
typedef interferes with the Template
template in the unnamed namespace. When you try to do Template<float>
in the global scope, the compiler raises an ambiguity error between the template name and the typedef name.
You don't have control over either the template name or the typedef-name. Now I want to know whether it is possible to:
- Create an object of the typedefed type
Template
(i.eTemplate<int>
) in the global namespace. - Create an object of the type
Template<float>
in the global namespace.
You are not allowed to add anything to the unnamed namespace. Everything should be done in the global namespace.
This is out of curiosity because i was wondering what tricks there are for solving such an ambiguity. It's not a practical problem i hit during daily programming.
© Stack Overflow or respective owner