Why do I get this error with "sort"?

Posted on 2011-03-05
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 125 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 125 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 125 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 34

Assisted Solution

sarabande earned 125 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 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

726 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