So, I'm trying to sort a vector
of a custom object myStruct
according to num1
in the structure.
I have to following code:
struct myStruct{
int num1;
std::vector<int> vecStruct;
int num2;
myStruct(int n1, std::vector<int> j, int n2) : num1(n1), vecStruct(j), num2(n2) {}
bool operator < (const myStruct& s) const
{
return (num1 < s.num1);
}
};
and then I use this to sort:
sort(myVector.begin(), myVector.end());
where
std::vector<myStruct> myVector;
I've tried to follow these instructions, but I keep getting a a compiling error:
No matching constructor for initialisation of 'myStruct'
I'm using Xcode 4.6.2 on MacOSX Mountain Lion - not that it matters, but Xcode is what's giving me this error