C++ :: Using Comparator In Set

Dec 12, 2012

I have the piece of code

Code:
#include<iostream>
#include<set>
using namespace std;
class Test {
public:
int val;
[Code] ....

gives following error

setTest.cpp: In function "int main()":
setTest.cpp:26: error: type/value mismatch at argument 2 in template parameter list for "template<class _Key, class _Compare, class _Alloc> class std::set"
setTest.cpp:26: error: expected a type, got "cmp"
setTest.cpp:26: error: invalid type in declaration before ";" token

My doubt is why we can only use functor and not predicate function. because in algorithms we can use both functor and predicate.

View 4 Replies


ADVERTISEMENT

C/C++ :: Sort String In Map Comparator Function

Jan 19, 2014

i am currently using a comparator function in STL map for sorting date of string data type in ascending value. My dates are in this format for e.g. 15OCT1990, 13SEP1980 and etc. I am using substring to split up the string so that i can compare day, month, year separately. Right now i have problem comparing the month portion because alphabetically "FEB" comes before "JAN".How can I make a fixed substring position of (2,3) which is my month value to accept that string value of JAN comes before FEB,AUG,DEC for e.g?

struct sortMapDaily: public std::binary_function <bool, std::string, std::string>
{
bool operator() (const std::string& lhs, const std::string& rhs)
{

[Code].....

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved