Re: std::sort crashes if more than 8 elements to be sorted.
In article <1146224414.762018.6730@g10g2000cwb.googlegroups.com>,
prakashsahni@gmail.com wrote:
I am using a sort func object like
struct mystruct {
bool operator () (MyClass* const &a, MyClass* const&b) {};
}
Invoke it like
std::sort(vec.begin(), vec.end(),mystruct);
Where vec is an std::vector<MyClass*>.
Everything works fine, except when my vector has more than 8 elements,
there is SEGV inside STL.
I am using Linux64(opteron), linux32(intel). gcc compiler
gcc/v3.2.3p1/bin/g++.
Is this a known issue/ bug , any way to fix this ?
There is nothing wrong with either vector or sort. Either you are doing
something wrong in your 'mystruct' or you are doing something wrong in
your "MyClass", or you are doing something wrong before the sort
function is called.
BTW you should be invoking it like:
std::sort( vec.begin(), vec.end(), mystruct() );
and use a sort func object like:
struct mystruct : std::binary_function< MyClass*, MyClass*, bool >
{
bool operator()( MyClass* a, MyClass* b ) const { }
};