Solved

Why do I get this error with "sort"?

Posted on 2011-03-05
10
623 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

914 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now