Click here to Skip to main content
15,899,124 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: microsoft document properties retreival code Pin
Maximilien12-Sep-06 6:38
Maximilien12-Sep-06 6:38 
AnswerRe: microsoft document properties retreival code Pin
David Crow12-Sep-06 7:08
David Crow12-Sep-06 7:08 
Questionhow to share the resource between two projects created in one workspace? Pin
bloodwinner12-Sep-06 5:57
bloodwinner12-Sep-06 5:57 
AnswerRe: how to share the resource between two projects created in one workspace? Pin
Waldermort12-Sep-06 6:46
Waldermort12-Sep-06 6:46 
QuestionStrange behaviour of close button Pin
Wim Engberts12-Sep-06 4:56
Wim Engberts12-Sep-06 4:56 
AnswerRe: Strange behaviour of close button Pin
Wim Engberts12-Sep-06 5:01
Wim Engberts12-Sep-06 5:01 
GeneralRe: Strange behaviour of close button Pin
Hamid_RT13-Sep-06 8:19
Hamid_RT13-Sep-06 8:19 
QuestionSorting a vector of a user defined type Pin
avimitrani12-Sep-06 4:21
avimitrani12-Sep-06 4:21 
Hi,

I am trying to apply the sort() algorithm on a vector of structs. I want the vector to be sorted according to one of the struct fields. I see two ways in which this could be done, and neither seems to work.

Here are the struct and the vector:
<br />
	struct item_calculation <br />
	{<br />
		int item_num;<br />
		float weight;<br />
		float contribution;<br />
		float prediction;<br />
	};<br />
<br />
               vector<item_calculation> found_items; 


I want the vector "found_items" to be sorted by the field "prediction".

The first way to do the task is defining a comparison function and sending it do sort() as a parameter:

	bool less_than( item_calculation a, item_calculation b ) {<br />
		return a.prediction < b.prediction;<br />
	};              <br />
.<br />
.<br />
.<br />
	sort(found_items.begin(), found_items.end(), less_than); 

This results with the errors: "error C3867: 'CCFEApp::less_than': function call missing argument list; use '&CCFEApp::less_than' to create a pointer to member."; "error C2780: 'void std::sort(_RanIt,_RanIt)' : expects 2 arguments - 3 provided"

when using "&CCFEApp::less_than" I get the error: "error C2914: 'std::sort' : cannot deduce template argument as function argument is ambiguous".

The second way to do the task is by overloading the "<" operator:

bool operator<(item_calculation a, item_calculation b) {<br />
    return a.prediction < b.prediction;<br />
};

gives: "error C2804: binary 'operator <' has too many parameters".

After changing to:
<br />
	bool operator<(item_calculation b) {<br />
		return prediction < b.prediction;<br />
	}; 

one gets: "error C2065: 'prediction' : undeclared identifier".

I would apreciate any help.

Thanks,
Avi.

P.S. I am working under Visual Studio 2005.
AnswerRe: Sorting a vector of a user defined type Pin
Rob Caldecott12-Sep-06 4:29
Rob Caldecott12-Sep-06 4:29 
GeneralRe: Sorting a vector of a user defined type Pin
avimitrani12-Sep-06 5:26
avimitrani12-Sep-06 5:26 
GeneralRe: Sorting a vector of a user defined type Pin
Rob Caldecott12-Sep-06 5:32
Rob Caldecott12-Sep-06 5:32 
GeneralRe: Sorting a vector of a user defined type Pin
avimitrani12-Sep-06 6:00
avimitrani12-Sep-06 6:00 
GeneralRe: Sorting a vector of a user defined type Pin
Zac Howland12-Sep-06 6:29
Zac Howland12-Sep-06 6:29 
GeneralRe: Sorting a vector of a user defined type Pin
avimitrani12-Sep-06 7:10
avimitrani12-Sep-06 7:10 
GeneralRe: Sorting a vector of a user defined type Pin
Zac Howland12-Sep-06 8:11
Zac Howland12-Sep-06 8:11 
AnswerRe: Sorting a vector of a user defined type [modified] Pin
Zac Howland12-Sep-06 4:30
Zac Howland12-Sep-06 4:30 
GeneralRe: Sorting a vector of a user defined type Pin
avimitrani12-Sep-06 5:14
avimitrani12-Sep-06 5:14 
GeneralRe: Sorting a vector of a user defined type Pin
Chris Losinger12-Sep-06 5:16
professionalChris Losinger12-Sep-06 5:16 
GeneralRe: Sorting a vector of a user defined type Pin
avimitrani12-Sep-06 5:42
avimitrani12-Sep-06 5:42 
GeneralRe: Sorting a vector of a user defined type Pin
Zac Howland12-Sep-06 5:40
Zac Howland12-Sep-06 5:40 
GeneralRe: Sorting a vector of a user defined type Pin
avimitrani12-Sep-06 5:49
avimitrani12-Sep-06 5:49 
GeneralRe: Sorting a vector of a user defined type Pin
Zac Howland12-Sep-06 6:17
Zac Howland12-Sep-06 6:17 
QuestionConvert from CStringW to CString Pin
zizzzz12-Sep-06 4:05
zizzzz12-Sep-06 4:05 
AnswerRe: Convert from CStringW to CString Pin
Rob Caldecott12-Sep-06 4:31
Rob Caldecott12-Sep-06 4:31 
GeneralRe: Convert from CStringW to CString Pin
zizzzz12-Sep-06 4:53
zizzzz12-Sep-06 4:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.