0

GCC 4.8 can't compile following code:

struct A {
  struct Impl;
  void f();
};

struct A::Impl {
  static int stat;
};

void A::f(){
  A::Impl::stat=1;
}

int main(int argc, char** argv) {
return 0;
}

and raise error:

cppbug.cpp:(.text+0xa): undefined reference to `A::Impl::stat' collect2: error: ld returned 1 exit status

but similar inline declaraton compiled as well:

struct A {
  struct Impl {
    static int stat;
  };

  void f(){
    A::Impl::stat=1;
  }
};

int main(int argc, char** argv) {
return 0;
}
slonma
  • 115
  • 1
  • 5
  • Your second version has the same problem, as soon you're going to create an instance for `A` and call `f()`. See here please: http://ideone.com/fwVEAb – πάντα ῥεῖ Dec 21 '14 at 07:59
  • Interesting. I have GCC 4.8.2 and second example was linked. But ideone.com have GCC 4.8.1 and it didn't. – slonma Dec 22 '14 at 07:01

0 Answers0