模板 c++ 中的静态 Class 对象
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);
};
Test::Global(5) 有错误;如何在模板中声明 class 对象实例?签名应该是什么?
template < int max >
struct Test { static Test global; };
template < int max >
Test<max>::global(5);
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) 有错误;如何在模板中声明 class 对象实例?签名应该是什么?
template < int max >
struct Test { static Test global; };
template < int max >
Test<max>::global(5);