[Bug c++/69387] undefined reference to constant in template
bernd.edlinger at hotmail dot de
gcc-bugzilla@gcc.gnu.org
Wed Jan 20 11:44:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69387
--- Comment #2 from Bernd Edlinger <bernd.edlinger at hotmail dot de> ---
Do you mean that is invalid?
class StatusCode
{
public:
static const int TEST_VALUE = 0x2;
};
I thought it is like defining
const int XXX = 123; which is actually only
a #define not a linker symbol.
I found that syntax in production code,
and it seems to be working everywhere, only
in the template context not, but it is working
other compilers.
We can write this declaration in the .h file
class StatusCode
{
public:
static const int TEST_VALUE;
};
and have this definition somewhere:
const int StatusCode::TEST_VALUE=2;
that works, but it means something completely different.
The value will be an extern const int in that case.
like
extern const int TEST_VALUE; // in .h file
and
extern const int TEST_VALUE=0x2; // at one place
More information about the Gcc-bugs
mailing list