0

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?

1
  • try not using the static keyword Commented Oct 16, 2014 at 22:07

1 Answer 1

1

Take "static" out of the definition:

Declaration:

class a
{
    static int Zero();
}

Definition:

int a::Zero()
{
    return 0;
}
Sign up to request clarification or add additional context in comments.

2 Comments

This solved the problem. But why can't I use static?
It's enough to declare the function as static. The same reason you don't need to specify the access type in the definition again - you say it's "public" in the header, for example, it's enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.