Compile error with class static member

This is very similar to previous post on this topic, but I am asking about one specific compiler link error I just can’t figure out.

As instructed in other similar posts I am creating a class to handle a timer interrupt via an ISR and to do so means I need a static function and in this case a static pointer to the class member function that will handle the ISR. I am including the working and broken code below.

My question is why when I initialize the member pointer in the class definition do I get a linking error but when I initialize it after the class definition does works?

The working version:

#include <TimerOne.h>

class A {

public:
//  static A *isr_instance=NULL;    // using this declaration of isr_instance causes link errors
  static A *isr_instance;           // using this declaration plus the initialization below seems to work, I don't understand.
  volatile unsigned long ticks=0;

  static void isr();
  void isr_function();

  A() {
    A::isr_instance = this;
  }

};

A *A::isr_instance=NULL;

static void A::isr() {
  if (A::isr_instance) A::isr_instance->isr_function();
}

void A::isr_function() {
  ticks++;
}

A *my_a;

void setup() {

  my_a = new A();
  Timer1.initialize(100000); // set a 1/10 of a second just to test this out.
  Timer1.attachInterrupt( A::isr ); // attach the service routine here
  Serial.begin(250000);
}

void loop() {

  static unsigned long last_print_ms = 0;
  static unsigned long cur_ms;

  cur_ms = millis();

  if (cur_ms - last_print_ms > 1000) {
    Serial.print(F("ticks: "));
    Serial.println(my_a->ticks++);
    last_print_ms = cur_ms;
    my_a->ticks = 0;
  }
}

The broken version (link error):

#include <TimerOne.h>

class A {

public:
  static A *isr_instance=NULL;    // using this declaration of isr_instance causes link errors
//  static A *isr_instance;           // using this declaration plus the initialization below seems to work, I don't understand.
  volatile unsigned long ticks=0;

  static void isr();
  void isr_function();

  A() {
    A::isr_instance = this;
  }

};

// have to remove this when initializing the variable in the class def
//A *A::isr_instance=NULL;

static void A::isr() {
  if (A::isr_instance) A::isr_instance->isr_function();
}

void A::isr_function() {
  ticks++;
}

A *my_a;

void setup() {

  my_a = new A();
  Timer1.initialize(100000); // set a 1/10 of a second just to test this out.
  Timer1.attachInterrupt( A::isr ); // attach the service routine here
  Serial.begin(250000);
}

void loop() {

  static unsigned long last_print_ms = 0;
  static unsigned long cur_ms;

  cur_ms = millis();

  if (cur_ms - last_print_ms > 1000) {
    Serial.print(F("ticks: "));
    Serial.println(my_a->ticks++);
    last_print_ms = cur_ms;
    my_a->ticks = 0;
  }
}

Here is the errors I get when I compile the second version.

/var/folders/dy/ks2g_6657gzdt7wbhhvq65bm0000gq/T//cc1Yn0Eu.ltrans0.ltrans.o: In function `isr':
/Users/jrule/Documents/Arduino/isr_class_test/isr_class_test.ino:23: undefined reference to `A::isr_instance'
/Users/jrule/Documents/Arduino/isr_class_test/isr_class_test.ino:23: undefined reference to `A::isr_instance'
/var/folders/dy/ks2g_6657gzdt7wbhhvq65bm0000gq/T//cc1Yn0Eu.ltrans0.ltrans.o: In function `A::A()':
/Users/jrule/Documents/Arduino/isr_class_test/isr_class_test.ino:14: undefined reference to `A::isr_instance'
/Users/jrule/Documents/Arduino/isr_class_test/isr_class_test.ino:14: undefined reference to `A::isr_instance'
collect2: error: ld returned 1 exit status
Multiple libraries were found for "TimerOne.h"
 Used: /Users/jrule/Documents/Arduino/libraries/TimerOne-master
exit status 1
Error compiling for board Arduino/Genuino Uno.

The only difference is in how the first variable ‘isr_instance’ is declared in the public section of the class. If I initialize it in the class it does not link correctly. If I initialize it external to the class block it does work. I thought these two should be equivalent. What am I not understanding about C++ classes and how to write them here? Thanks in advance for any help.

By the way, I have tested the code and the ISR routine works great this way. It is Implemented as a class using a static member and a static member function.​

You can't initialize a non-constant static member with the class declaration. I'll defer to the C++ gurus to explain why.

It's kinda-sorta related to the notion that class definitions get put in .h files, and initializers need to be executed.

Say Foo.h contains

// FOO.h

class Foo {
  static int bar = perform_some_calculation();
};

That initialization would have to be performed when, exactly? How many times? Recall that once a .h is included by the preprocessor, it just looks to the compiler like inline code.

Languages with proper classes don't have this problem, of course.