I want to create a static constant by streaming into a default-constructed object. However, the compiler cannot locate the streaming operator, although I provide it:
QMap<float, int>& operator<<(QMap<float, int>& map,
const QPair<float, int>& data)
{
(void) map.insert(data.first, data.second);
return map;
}
static const QMap<float, int> s_Map
= QMap<float, int>() << QPair<float,int>(1.0,0);
For contrast, the following code compiles (“works” would be too strong a word)
QMap<float, int>& operator<<(QMap<float, int>& map,
const QPair<float, int>& data)
{
(void) map.insert(data.first, data.second);
return map;
}
// Intermediate variable
static QMap<float, int> s_tempMap;
static const QMap<float, int> s_Map
= s_tempMap << QPair<float,int>(1.0,0);
Why doesn’t the first version compile?
I’m using the MinGW provided with Qt 4.8 (4.4.0)
EDIT:
Completely forgot to post the error message:
error: no match for ‘operator<<’ in ‘QMap<float, int>() << QPair<float, int>(((const float&)((const float*)(&1.0e+0f))), ((const int&)((const int*)(&0))))’
candidates are: QMap<float, int>& operator<<(QMap<float, int>&, const QPair<float, int>&)
↧