开发者

C++ Nested Template Class Method Issue

开发者 https://www.devze.com 2023-03-31 07:16 出处:网络
I\'m having a problem with the method declaration for a nested class template. I have something like this:

I'm having a problem with the method declaration for a nested class template. I have something like this:

template <typename T>
class HashTrie
{
    template <typename Y>
    class Entry
    { // members and methods here
    };

    template <typename U>
    class Node
    { // members and methods here
    };

     // members and methods here
}

The following seems to work without a problem:

template <typename T>
template <typename Y>
HashTrie<T>::Entry<Y> HashTrie<T>::Entry<Y>::someMethod() {
    //...
}

However, this does not:

template <typename T>
template <typename U>
std::map<char, HashTrie<T>::Node<U> > HashTrie<T>::Node<U>::anotherMethod() {
// ...
}

I get the following error on GCC

./HashTrie.h:389: error: type/value mismatch at argument 2 in template parameter list for ‘template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map’
./HashTrie.h:389: error:   expected a type, got ‘(HashTrie::Node < <expression error>)’
./HashTrie.h:389: error: template argument 4 is invalid
./HashTrie.h:389: error: expected unqualified-id before ‘>’ token

I tried adding a typename, but that doesn't seem to help

template <typename T>
template <typename U>
std::map<char, typename HashTrie<T>::Node<U> > HashTrie<T>::Node<U>::anotherMethod() {
// ...
}

results in...

./HashTrie.h:389: error: template argument 2 is invalid
./HashTrie.h:389: error: template argument 4 is invalid
./HashTrie.h:389: error: expected unqualified-id before ‘>’ token

icpc says:

./HashTrie.h(389): error: template parameter "HashTrie<T>::Node [开发者_如何学Pythonwith T=T]" may not have a template argument list
    std::map<char, typename HashTrie<T>::Node<U> > HashTrie<T>::Node<U>::newNodeMap() {

I'm not really sure what to do here, and had a hard time finding any similar problems across the web. Any help would be appreciated.


Say this:

template <typename T>
template <typename U>
std::map<char, typename HashTrie<T>::template Node<U> > HashTrie<T>::Node<U>::foo()
{
}
0

精彩评论

暂无评论...
验证码 换一张
取 消