C++11 实现类的静态方法

C++11 实现类的静态方法,c++11,static-methods,C++11,Static Methods,我有一个标题: class a { public: a(); static int Zero(); void SimpleEx(); } 及其cpp文件: a() { } static int a::Zero() {return 0;} void SimpleEx() { cout << a::Zero(); } a(){} 静态int a::Zero(){return 0;} void SimpleEx(){cout从定义中去掉“static”: int a::Z

我有一个标题:

class a
{
 public:
  a();
  static int Zero();
  void SimpleEx();
}
及其cpp文件:

a() { }
static int a::Zero() {return 0;}
void SimpleEx() { cout << a::Zero(); }
a(){}
静态int a::Zero(){return 0;}
void SimpleEx(){cout从定义中去掉“static”:

int a::Zero()
{
    return 0;
}
声明:

class a
{
    static int Zero();
}
定义:

int a::Zero()
{
    return 0;
}

尝试不使用static关键字这解决了问题。但是为什么我不能使用static?将函数声明为static就足够了。同样的原因是,您不需要在定义中再次指定访问类型-例如,您在标题中说它是“public”,这就足够了。