c++ - g++ rejects my simple functor with "expected a type, got 'xyz'" -


I am playing with functors in C ++, in particular, I have a pair of pairs of which I I want to sort by first element. I had started writing something like a completely special motive (i.e. "Bull Myelaceanthan (MyPair and LHS, MyPairs and R & Ss"). Then, just because such things are interesting, I try to write a general " I wanted to "Apply F for the first elements of this pair" Factor I wrote below, but G ++ does not like it. I found:

Error: 'Template Structure Pair 1stFunc2' error For tame Type / value mismatch on argument 2 in the slate parameter list: Exclude a type, 'less' found

  # include & lt; algorithm & gt; #include & lt; functional & gt; # Include & lt; utility & gt; #include & lt; vector & gt; template & lt; class p, class f> Struct Pair1stFunc2 {typename F :: Results_type operator (P & amp; LHS, P & Amp; RS) const {return F (lhs.first, rhs.first);} Type name F :: Results_type operator (Const P & LHS, Const P & RA) Const {Return F (LA) F.fast, rasf);}}; typedef std :: pair  mypair; type-up speed :: vector & lt; MyPair & gt; MyPairList; MyPairList pairs; Zero foo (zero) {std :: sort (pairs.begin (), pairs.end (), Pair 1stFunc2 & lt; MyPair, std :: less> ()); }  

What am I doing wrong here but can put any light on it? I know that this is a little artificial example, but I would like to know what is going on, if only my STL-Fu improves.

requires std :: less expertise with the comparison type you use.

  Pair1stFunc2 & lt; MyPair, std :: less & lt; Int & gt; & Gt; ()  

The trick will be performed. Within your own operator () you have to instantinate the type of object, because you can not directly call the class like change

return F (lhs.first, rhs.first );

to

  F function; Return funk (lhs.first, rhs.first);  

You can also transfer expertise in the brain, as one suggestion suggests.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -