C++嵌套模板类方法问题

发布于 2024-12-01 05:10:15 字数 1964 浏览 1 评论 0原文

我在嵌套类模板的方法声明方面遇到问题。 我有这样的事情:

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
}

以下似乎工作没有问题:

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

但是,这不是:

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

我在 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

我尝试添加类型名,但这似乎没有帮助

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

结果...

./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 说:

./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() {

我不太确定在这里做什么,并且很难在网络上找到任何类似的问题。任何帮助将不胜感激。

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 [with 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

坏尐絯℡ 2024-12-08 05:10:15

这么说:

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

Say this:

template <typename T>
template <typename U>
std::map<char, typename HashTrie<T>::template Node<U> > HashTrie<T>::Node<U>::foo()
{
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文