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

C / C++ / MFC

 
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 
Your code just needs to be modified slightly:

// struct definition
struct item_calculation
{
	int item_num;
	float weight;
	float contribution;
	float prediction;

	item_calculation() : item_num(0), weight(0.0), contribution(0.0), prediction(0.0)
	{}
};

// this is actually a better way of doing it
bool operator< (const item_calculatioin& lhs, const item_calculation& rhs)
{
	return lhs.prediction < rhs.prediction;
}

// sort call
sort(found_items.begin(), found_items.end());	// less<item_calculation> is the default predicate



-- modified at 10:49 Tuesday 12th September, 2006

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

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 
GeneralRe: Convert from CStringW to CString Pin
Rob Caldecott12-Sep-06 4:58
Rob Caldecott12-Sep-06 4:58 
AnswerRe: Convert from CStringW to CString Pin
Rinu_Raj12-Sep-06 4:35
Rinu_Raj12-Sep-06 4:35 
GeneralRe: Convert from CStringW to CString Pin
zizzzz12-Sep-06 5:21
zizzzz12-Sep-06 5:21 
GeneralRe: Convert from CStringW to CString Pin
David Crow12-Sep-06 7:15
David Crow12-Sep-06 7:15 
AnswerRe: Convert from CStringW to CString Pin
wiemounir12-Sep-06 5:17
wiemounir12-Sep-06 5:17 
GeneralRe: Convert from CStringW to CString Pin
Hamid_RT13-Sep-06 8:11
Hamid_RT13-Sep-06 8:11 
GeneralRe: Convert from CStringW to CString Pin
wiemounir13-Sep-06 23:06
wiemounir13-Sep-06 23:06 
GeneralRe: Convert from CStringW to CString Pin
Hamid_RT13-Sep-06 23:33
Hamid_RT13-Sep-06 23:33 

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.