Is this legal C++?
template <typename T, template <typename T> class>
struct S { };
Clang (3.7.1) rejects it, complaining the second T
shadows the first T
. GCC seems not to care about it and I think that's reasonable. I think it is only the number of parameters that matters in a template template parameter.
No. [temp.local]/6 :
A template-parameter shall not be redeclared within its scope (including nested scopes).
While the right answer exists, it toke some time for myself to understand, and I just wanted to add an example:
template <class Key, class T>
class MyData {
public:
// ...
template <class Key, class T>
inline static MyData<Key, T> *get(MyMap<Key, T> *ptr)
{
return NULL: // Logic here...
}
// ...
}
As " Template-parameters shall not be re-declared within its scope (including nested scopes)
", above get(..)
method should be changed and use other names, like:
template <class KeyType, class Type>
inline static MyData<KeyType, Type> *get(MyMap<KeyType, Type> *ptr)
{
return NULL: // Logic here...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.