模板c ++中的静态类对象

时间:2016-12-05 18:16:48

标签: c++ templates static-classes

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)上有错误;如何在模板中声明类对象实例?签名应该是什么?

1 个答案:

答案 0 :(得分:0)

template < int max >
struct Test { static Test global; };

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