vendredi 19 février 2021

why c++ const char array assign not works

#include <stdlib.h>
#include <iostream>
struct A {
  static constexpr const char *a = "HELLO";
  static constexpr const char b[] = "HELLO";
};

struct X {
  static constexpr const char * VXX = A::a;
};

int main()
{
   std::cout<<A::b<<std::endl;
   std::cout<<X::VXX<<std::endl;
   return 0;
}

compile will failure:

$g++ a.cc -std=c++11
/tmp/cc31F0ck.o: In function `main':
a.cc:(.text+0x5): undefined reference to `A::b'
collect2: error: ld returned 1 exit status

Aucun commentaire:

Enregistrer un commentaire