This issue is reproducible in the g++ prior to -std=c++14
. A linking error is generated due to highlighted const
shown in below codes. It disappears, if the RHS const
is removed.
/* main.cpp */
const char* const arr[2] = {"Hello", "World"};
// ^^^^^
int main () {}
and
/* foo.cpp */
extern const char* const arr[2];
// ^^^^^
void foo () {
const char* p = arr[1];
}
While compiling: g++ [-std=c++11] main.cpp foo.cpp
, it gives following linking error:
In function `foo()': undefined reference to `arr'
Is it a bug or a language limitation?
Aucun commentaire:
Enregistrer un commentaire