Aaron Azhari
Aaron Azhari

Reputation: 987

implement a static method of a class

I have a header:

class a
{
 public:
  a();
  static int Zero();
  void SimpleEx();
}

and its cpp file:

a() { }
static int a::Zero() {return 0;}
void SimpleEx() { cout << a::Zero(); }

I get the error when compiling:

Error 1 error LNK2019: unresolved external symbol "public: static class a __cdecl a::Zero(void)" (?Zero@a@@SA?AV1@XZ) referenced in function "public: class a __thiscall a::SimpleEx(void)" (?SimpleEx@a@@QAE?AV1@XZ)

How to solve this?

Upvotes: 0

Views: 72

Answers (1)

Ian
Ian

Reputation: 1251

Take "static" out of the definition:

Declaration:

class a
{
    static int Zero();
}

Definition:

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

Upvotes: 1

Related Questions