Trying to use static const members in functions qMin(), qMax(), qBound() gives a linker error:
undefined reference to `<the static constant>'.
Here is an example code:
class Test
{
public:
static const float KValue=3.0;
Test();
};
Test::Test()
{
// Can be any function, not only a constructor
float foo = 1.0;
foo = qMax( foo, KValue );
}
int main()
{
// somewhere in a program
Test obj;
}
class Test
{
public:
static const float KValue=3.0;
Test();
};
Test::Test()
{
// Can be any function, not only a constructor
float foo = 1.0;
foo = qMax( foo, KValue );
}
int main()
{
// somewhere in a program
Test obj;
}
To copy to clipboard, switch view to plain text mode
On the other hand, when using usual local constants, qMax (and friends) works ok:
float foo = 1.0;
const float value = KValue; // Make a copy of the static constant
foo = qMax( foo, value );
float foo = 1.0;
const float value = KValue; // Make a copy of the static constant
foo = qMax( foo, value );
To copy to clipboard, switch view to plain text mode
Please write, if someone knowswhy this happens or any good workarounds.
Sytem info:
Kubuntu 8.04
Qt 4.4.0 and 4.4.1
gcc 4.2.4
Bookmarks