8
Mam problem z deklaracją metody dla zagnieżdżonego szablonu klasy. mam coś takiego:C++ Zagnieżdżona metoda klasy szablonów Problem
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
}
Poniższy wydaje się działać bez problemu:
template <typename T>
template <typename Y>
HashTrie<T>::Entry<Y> HashTrie<T>::Entry<Y>::someMethod() {
//...
}
Jednak to nie:
template <typename T>
template <typename U>
std::map<char, HashTrie<T>::Node<U> > HashTrie<T>::Node<U>::anotherMethod() {
// ...
}
pojawia się następujący błąd na 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
Próbowałem dodanie TypeName, ale to nie wydaje się, aby pomóc
template <typename T>
template <typename U>
std::map<char, typename HashTrie<T>::Node<U> > HashTrie<T>::Node<U>::anotherMethod() {
// ...
}
wyniki w ...
./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 mówi:
./HashTrie.h(389): error: template parameter "HashTrie<T>::Node [with T=T]" may not have a template argument list
std::map<char, typename HashTrie<T>::Node<U> > HashTrie<T>::Node<U>::newNodeMap() {
nie jestem pewien co tu robić i trudno było znaleźć podobne problemy w sieci. Każda pomoc będzie doceniona.
Dziękuję bardzo! – Dan