【问题标题】:Static Class Object in template c++模板c ++中的静态类对象
【发布时间】:2017-04-20 05:29:57
【问题描述】:
template<int max_number> class Test {

    private:

    // static object definition
    static Test Global;

    public:

   // constructor
    Test(int x){
    int y;
    y = x;
    }
    //static object definition inside template
    Test::Global(5);

    };

Test::Global(5) 有错误;如何在模板中声明类对象实例?应该是什么签名?

【问题讨论】:

  • 你没有显示错误信息

标签: c++ templates static-classes


【解决方案1】:
template < int max >
struct Test { static Test global; };

template < int max >
Test<max>::global(5);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多