it's a pretty basic question but I don't understand why the code below does not compile on GCC 4.6.1. It does compile on VS 2008 with SP1:
#include <iostream>
class MyClass
{
public:
const static int MinValue = -1000;
const static int MaxValue = 1000;
};
void printValue(int i)
{
std::cout << i << std::endl;
}
int main(int argc, char** argv)
{
printValue(MyClass::MinValue);
printValue(MyClass::MaxValue);
printValue(argc < 42 ? MyClass::MinValue : MyClass::MaxValue); //This line gives the error
}
GCC says:
david@David-Laptop:~/temp$ g++ test.cpp
/tmp/ccN2b95G.o: In function `main':
test.cpp:(.text+0x54): undefined reference to `MyClass::MinValue'
test.cpp:(.text+0x5c): undefined reference to `MyClass::MaxValue'
collect2: ld returned 1 exit status
However, if I take out the third call to 'printValue' then it builds and runs properly. So it's something to do with the '?' operator... is it not valid to use it like this? Also, if I replace the 'argc < 42' with 'true' or 'false' it also builds fine.
Any ideas?!