Solved

Why do I get this error with "sort"?

Posted on 2011-03-05
10
616 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 32

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

760 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

21 Experts available now in Live!

Get 1:1 Help Now