Search code examples
c++templatesstatic-classes

Static Class Object in template c++


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);

    };

There is error on Test::Global(5); How can I declare class object instance in template? What signature should be?


Solution

  • template < int max >
    struct Test { static Test global; };
    
    template < int max >
    Test<max>::global(5);