Solved

Why do I get this error with "sort"?

Posted on 2011-03-05
10
632 Views
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:

http://www.cplusplus.com/reference/algorithm/sort/

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?
0
Comment
Question by:shaolinfunk
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 32

Accepted Solution

by:
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?
0
 
LVL 1

Assisted Solution

by:hogwell
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.

0
 
LVL 12

Assisted Solution

by:trinitrotoluene
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?
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
LVL 33

Assisted Solution

by:sarabande
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.

Sara

0
 
LVL 1

Author Comment

by:shaolinfunk
ID: 35055053
@trinitroluene

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.
0
 
LVL 12

Expert Comment

by:trinitrotoluene
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
0
 
LVL 1

Author Comment

by:shaolinfunk
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.
0
 
LVL 32

Expert Comment

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

Author Comment

by:shaolinfunk
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.
0
 
LVL 1

Author Comment

by:shaolinfunk
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.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

832 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