N
Nick Battle
I was surprised to find the code below won't link, though both
compilers I have (g++ and aCC) give the same result so it's presumably
not a bug. Is this the problem, I've read elsewhere, about template
args having to have external linkage? But then why does the commented
out inline version work? Any help appreciated...
template <typename T> const T &max(const T &a, const T &b)
{
return (a > b ? a : b);
}
class C
{
public:
C(void); // THIS WORKS { int x = max(456, value); }
static const int value = 123;
};
C::C(void) { int x = max(456, value); } // THIS FAILS
int main(int, char *[]) { }
The linkage error is that it fails to resolve C::value.
compilers I have (g++ and aCC) give the same result so it's presumably
not a bug. Is this the problem, I've read elsewhere, about template
args having to have external linkage? But then why does the commented
out inline version work? Any help appreciated...
template <typename T> const T &max(const T &a, const T &b)
{
return (a > b ? a : b);
}
class C
{
public:
C(void); // THIS WORKS { int x = max(456, value); }
static const int value = 123;
};
C::C(void) { int x = max(456, value); } // THIS FAILS
int main(int, char *[]) { }
The linkage error is that it fails to resolve C::value.