Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Why do I get this error with "sort"?

Posted on 2011-03-05
Medium Priority
Last Modified: 2013-12-14
The line of code is simply this:
sort(vVector1.begin(), vVector1.end(), SortVectorbySize);

Here's my problem.  I cut & pasted this line from another project where that one compiled without any problems with this line of code.....But in this project I get this error..

1>c:\documents and settings\administrator\desktop\copy of firstapp\firstapp\function.cpp(545) : error C2780: 'void std::sort(_RanIt,_RanIt)' : expects 2 arguments - 3 provided
1>        c:\program files (x86)\microsoft visual studio 9.0\vc\include\algorithm(3110) : see declaration of 'std::sort'

I looked up this website:


And it shows that the 3rd parameter can be a compare parameter...which is what it was in the other project that compiles successfully...why won't it work in my new project?
Question by:shaolinfunk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
LVL 32

Accepted Solution

phoffric earned 500 total points
ID: 35045082
Do you have another sort defined in your project?

Did you #include <algorithm> in your .cpp file?

If you right-click on "sort" and say go to definition, does it pick up only a 2 argument sort?

Does std::sort(...) solve the problem?

Does SortVectorbySize() take the same type as what the vector is holding?

Can you post a short (or long) program that reproduces the compiler error?

Assisted Solution

hogwell earned 500 total points
ID: 35048007
Check the definition of SortVectorBySize.
Is it a function returning bool that takes two arguments that are the same as the elements of vVector1?

Perhaps the #include order has changed when you moved to the new compiler and the wrong SortVectorBySize definition is getting pulled in.

LVL 12

Assisted Solution

trinitrotoluene earned 500 total points
ID: 35051196
>>>>>"what it was in the other project that compiles successfully...why won't it work in my new project"

has SortVectorbySize() been defined in your current project?
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 35

Assisted Solution

sarabande earned 500 total points
ID: 35055035
in <algorithm> of vc9 stl at line 3273 is a second template sort function taking a compare function as 3rd argument. so wrong stl version is not the problem but most likely wrong or missing prototype of sort function.



Author Comment

ID: 35055053

Yes, SortVectorbySize has been brought over from the working project into this current project, and defined.  It was cut & pasted verbatim.

I am still looking into this issue at this very moment...thanks for the helpful suggestions.
LVL 12

Expert Comment

ID: 35063001
>>>error C2780: 'void std::sort(_RanIt,_RanIt)'

for some reason the compiler thinks you are calling the 2 argument function so this could be because it doesn't recognise your 3rd argument as a function pointer.

Try renaming the SortVectorbySize() function, make requisite changes in its prototype and definition and then use it in your std::sort call. See what error you get this time

Author Comment

ID: 35063246
Ok.  Acknowledged...I am still working on this problem, so I thank you for your input.  

Currently, I am debugging my way through my little app by creating an output log that will help me view more clearly what is going on.  I have some suspicions but cannot confirm until I see all of the output.
LVL 32

Expert Comment

ID: 35063399
>> Currently, I am debugging my way through my little app
How did you build the program with that compiler error?

Author Comment

ID: 35066981
I didn't build with the error...I commented out the code causing the error and then built it.  

Once I can view the output at each step of my code I will eventually un-comment the error.

Author Comment

ID: 35072936
After a lot of debugging I found my error.

In my NEW project's header file SortVectorbySize() did NOT have static in front of it.  In the older project header file, where the code works, it did have static in front of it.

Thank you all for your clues...it definitely helped.  Everyone gets points.

Now, if someone could help me understand what 'static' does......I'll post that question in a new thread soon after I assign points.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question