0

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?
Unresolved external symbol C++

I know that you can have static locals and static globals, but is it possible to have static fields? I ask because when I declare a static field (a static variable declared inside a class) I get "unresolved externals" compiler error messages.

Community
  • 1
  • 1
John Smith
  • 4,416
  • 7
  • 41
  • 56
  • Yes. Just been answered earlier today. See [here][1] [1]: http://stackoverflow.com/questions/13660017/unresolved-external-symbol-c/13660035#13660035 – Ed Heal Dec 01 '12 at 14:22
  • we unable to answer if you don't put your code or what you did ? ? Here is some reference it might helps you. 1. http://stackoverflow.com/questions/195207/unresolved-external-symbol-on-static-class-members 2. http://stackoverflow.com/questions/7510165/c-static-variable-and-unresolved-externals-error – immayankmodi Dec 01 '12 at 14:27

1 Answers1

3

Yes, it is possible. What you have to do is define the static member. Typically this is done in the corresponding .cpp file:

//=== C.h

class C {
  static int i; // declaration
}

//=== C.cpp

#include <C.h>

int C::i = 0;   // definition
NPE
  • 486,780
  • 108
  • 951
  • 1,012