I've encountered a problem (well, lack of knowledge) with sorting Mems.
Code:
class A
{
public:
int x;
int getX()
{
return x;
}
};
Mems<A> container;
Edit:
I figured out how to sort it, but there's 1 more thing I'd like to know.
I want the container to sort by x variable, so I call container.sort(customSort).
That's how it looks like:
Code:
Int customSort(C A &a, C A &b)
{
if(a.x<b.x)
return 1;
else
return -1;
}
It works fine, but if I use a.getX() instead of a.x, I get an error:
Code:
1>Source\Main.cpp(153): error C2662: 'I32 A::getX(void)' : cannot convert 'this' pointer from 'const A' to 'A &'
1> Conversion loses qualifiers
What's the problem here?
Edit2:
Ok, solved it.
Int customSort(C A &a, C A &b) takes arguments as consts, so I couldn't use A class non-const functions in it. The solution was to either const_cast object a in customSort function or to make the getX() function const (which is better I guess).
Edit3:
How can I make it work with container of pointers?