I am using gcc (Debian 4.4.5-8) 4.4.5. with the following code, I am getting linking error :
/tmp/ccOeGgC9.o: In function
A::func()':
B::CONST_B'
(.text+0x1b): undefined reference to
(.text+0x23): undefined reference to `A::CONST_A'
header:
class A {
public:
static const int CONST_A = 10;
int func();
};
class B {
public:
static const int CONST_B = 20;
};
cpp file (with linking error):
int A::func() {
bool c = true;
const int a = (c == true) ? B::CONST_B : CONST_A;
}
int main() {
return 0;
}
to fix the error, I have to write cpp file follow:
cpp file(working):
int A::func() {
bool c = true;
int a = CONST_A;
a = (c == true) ? B::CONST_B : a;
}
int main() {
return 0;
}
can you please explain why I can't compile first code?