D
drazse
I had a puzzling compiler error, which I was able to resolve after
some experimentation, but it still troubles me. I was able to isolate
the problem to a couple of lines.
Could someone explain what's wrong with the following code, please?
//=================================
#include <algorithm>
namespace NS {
struct C2
{
C2(int n) : value(n) {}
int value;
};
} // namespace NS
#ifndef WORKS
bool operator < (const NS::C2& s1, const NS::C2& s2)
{
return s1.value < s2.value;
}
#else
namespace NS {
bool operator < (const C2& s1, const C2& s2)
{
return s1.value < s2.value;
}
}
#endif
int main()
{
std:air<int, NS::C2> p1(3, 7);
std:air<int, NS::C2> p2(3, 8);
bool cmp1 = p1.second < p2.second; // OK
bool cmp2 = p1 < p2; // ERROR
return cmp2;
}
//=================================
Compiler output:
$ g++-4.3.2 paircmp.C
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_pair.h:
In function ‘bool std:perator<(const std:air<_T1, _T2>&, const
std:air<_T1, _T2>&) [with _T1 = int, _T2 = NS::C2]’:
paircmp.C:33: instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_pair.h:
159: error: no match for ‘operator<’ in ‘__x->std:air<int,
NS::C2>::second < __y->std:air<int, NS::C2>::second’
BTW, if I compile it with -DWORKS, it compiles w/o any errors.
some experimentation, but it still troubles me. I was able to isolate
the problem to a couple of lines.
Could someone explain what's wrong with the following code, please?
//=================================
#include <algorithm>
namespace NS {
struct C2
{
C2(int n) : value(n) {}
int value;
};
} // namespace NS
#ifndef WORKS
bool operator < (const NS::C2& s1, const NS::C2& s2)
{
return s1.value < s2.value;
}
#else
namespace NS {
bool operator < (const C2& s1, const C2& s2)
{
return s1.value < s2.value;
}
}
#endif
int main()
{
std:air<int, NS::C2> p1(3, 7);
std:air<int, NS::C2> p2(3, 8);
bool cmp1 = p1.second < p2.second; // OK
bool cmp2 = p1 < p2; // ERROR
return cmp2;
}
//=================================
Compiler output:
$ g++-4.3.2 paircmp.C
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_pair.h:
In function ‘bool std:perator<(const std:air<_T1, _T2>&, const
std:air<_T1, _T2>&) [with _T1 = int, _T2 = NS::C2]’:
paircmp.C:33: instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.3.2/include/g++-v4/bits/stl_pair.h:
159: error: no match for ‘operator<’ in ‘__x->std:air<int,
NS::C2>::second < __y->std:air<int, NS::C2>::second’
BTW, if I compile it with -DWORKS, it compiles w/o any errors.