【问题标题】:How to initialize static field in template class with type of inner class如何使用内部类的类型初始化模板类中的静态字段
【发布时间】:2013-04-06 01:42:49
【问题描述】:

我有这样的事情

template <class T>
class Outer {
    public: class Inner;

    static Inner* x;

    //...

    class Inner {
        //...
    };
};

// Not working
template <class T>
Outer<T>::Inner* Outer<T>::x = NULL;

我得到的错误是::16: error: expected constructor, destructor, or type conversion before ‘*’ token

【问题讨论】:

  • 也许是typename

标签: c++ templates static-initialization


【解决方案1】:
template<class T>
class Outer {
public: 

    class Inner;

    static Inner* x;

    //...

    class Inner {
        //...
    };
};

template<class T>
typename Outer<T>::Inner *Outer<T>::x = NULL;
  1. typenameclass请参考C++ difference of keywords 'typename' and 'class' in templates

  2. 这是为什么,请参考Trouble with dependent types in templates

【讨论】:

    猜你喜欢
    • 2011-01-19
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多