cannot overload allocator because cannot define "less"
Dec 3, 2012 at 7:14pm UTC
Have next piece of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
typedef struct _TMovedMols
{
private :
union
{
uint32_t dummy;
struct
{
unsigned int UniqueMolID:31;
unsigned int Direction:1;
};
};
public :
_TMovedMols(int AUniqueMolID=0, int ADirection=0)
{
UniqueMolID=AUniqueMolID;
Direction=ADirection;
}
_TMovedMols(const _TMovedMols &other)
{
dummy=other.dummy;
}
inline _TMovedMols & operator = (const _TMovedMols &other)
{
dummy=other.dummy;
return *this ;
}
inline bool operator < (const _TMovedMols &other) const
{
return UniqueMolID < other.UniqueMolID;
}
} TMovedMols;
class TLocalSetAllocator ...;
typedef std::set<TMovedMols, less <TMovedMols>, TLocalSetAllocator<TMovedMols> > my_set_t;
Obtained
test_set.cpp:146:3: error: ‘less’ was not declared in this scope
test_set.cpp:146:3: note: suggested alternative:
It's very first error form compiler, so no history. Does "less" supposed to be synonim to "<"?
Dec 3, 2012 at 7:17pm UTC
It's
std::less
, and it is defined in the include file
<functional>
(incidentally, why define your struct as both
_TMovedMols
and
TMovedMols
? One name is enough)
To quote clang++,
test.cc:42:30: error: no template named 'less'; did you mean 'std::less'?
typedef std::set<TMovedMols, less <TMovedMols>,...
^~~~
std::less
also, regarding your struct inside a union inside TMovedMols,
test.cc:10:13: error: anonymous structs are a GNU extension
[-Werror,-pedantic,-Wgnu]
struct
^
Last edited on Dec 3, 2012 at 7:26pm UTC
Dec 3, 2012 at 7:34pm UTC
You haven't namespace-qualified "less". It should be
std::less
.
According to the documentation on this very site:
http://www.cplusplus.com/reference/functional/less/
less
is a template for a function object - that is, an object whose () operator has been overridden to return a value. The
less
template overrides the () operator to return the results of a < comparison between its two arguments.
In other words, if you create an object:
std::less<MyType> lessObj;
and:
1 2 3 4
MyType a;
MyType b;
/* Set the values of a and b */
then
gives the same result as:
Topic archived. No new replies allowed.