Nope, in my second example I keep using the same static const float. It's initialized inside the class and used very well inside the later code, but not in function qMax. I am already beginning to suspect that the error occurs because qMax() takes its arguments by reference (not value). Something wrong, when passing address of a static constant to a function.
Here is the same example 2, but at its full glory. It works, no error here:
class Test
{
public:
static const float KValue=3.0;
Test();
};
Test::Test()
{
// Can be any function, not only a constructor
float foo = 1.0;
const float value = KValue; // Make a copy of the static constant
foo = qMax( foo, value );
}
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;
const float value = KValue; // Make a copy of the static constant
foo = qMax( foo, value );
}
int main()
{
// somewhere in a program
Test obj;
}
To copy to clipboard, switch view to plain text mode
I've also noticed the following facts:
* Changing from float to int doesn't change the situation a bit.
* Using "normal" functions that take arguments by value (not by reference) doesn't lead to the error. Such functions can easily take static constants as arguments.
Bookmarks