Click here to Skip to main content
16,004,969 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Subclassing or Derviving Pin
monrobot1311-Feb-04 10:04
monrobot1311-Feb-04 10:04 
GeneralStrange memory overrun Pin
John R. Shaw10-Feb-04 10:43
John R. Shaw10-Feb-04 10:43 
GeneralRe: Strange memory overrun Pin
Tom Larsen10-Feb-04 11:30
Tom Larsen10-Feb-04 11:30 
GeneralRe: Strange memory overrun Pin
John R. Shaw10-Feb-04 12:37
John R. Shaw10-Feb-04 12:37 
GeneralRe: Strange memory overrun Pin
Tom Larsen11-Feb-04 5:00
Tom Larsen11-Feb-04 5:00 
QuestionHow to adding "Start parameters" to a Window service Pin
sysmatrix10-Feb-04 10:09
sysmatrix10-Feb-04 10:09 
AnswerRe: How to adding "Start parameters" to a Window service Pin
Peter Weyzen10-Feb-04 11:31
Peter Weyzen10-Feb-04 11:31 
GeneralDoubts with sorting stl vector... Pin
Cloaca10-Feb-04 9:32
Cloaca10-Feb-04 9:32 
Hi everyone,

I have a class like this:

// Header file
class CFoo
{
public:
	CFoo();
	~CFoo();
	BOOL SortByName();
	// Other functions declared here...

protected:
	std::vector<CRec*> m_Recs; // CRec is a class with CStrings, etc.

private:
	struct NameComparer
	{
		bool operator()(const CRec* A,const CRec* B)
		{
			return ((A->m_strName) < (B->m_strName));
		}
	};
};


// CPP file
// Other functions are defined here...
BOOL CFoo::SortByName()
{
	std::stable_sort(m_Recs.begin(), m_Recs.end(), NameComparer());

	return TRUE;
}


Now, basically, I am trying to properly write and use a predicate function (I think that's what they're called; please correct me if I'm wrong) in the context of calling std::stable_sort (and just std::sort for that matter). There are many helpful examples around, but they don't seem to cover dealing with a non-trivial class (or if they do I haven't 'gotten it' yet).
In my case, I want to be able to sort the vector of CRec's according to several different CRec member variables (different CStrings, ints, doubles, etc.). My questions are:
1) Did I use proper coding techniques to solve the problem as I have shown here?
2) Is it the case that I need to add additional structs under the private section of CFoo for each comparison CFoo member function I want to write (with the comparisons applied to the std::vector m_Recs and based on the CRec members themselves actually)?
3) Why do I need to wrap the comparison functions in a struct? How does that fact relate to operator(), etc.?

Thank you all again for reading and giving any advice,
Best, Smile | :)
Eric
GeneralRe: Doubts with sorting stl vector... Pin
David Crow10-Feb-04 10:05
David Crow10-Feb-04 10:05 
GeneralRe: Doubts with sorting stl vector... Pin
Cloaca10-Feb-04 10:14
Cloaca10-Feb-04 10:14 
GeneralRe: Doubts with sorting stl vector... Pin
David Crow10-Feb-04 10:34
David Crow10-Feb-04 10:34 
GeneralRe: Doubts with sorting stl vector... Pin
Cloaca11-Feb-04 6:48
Cloaca11-Feb-04 6:48 
GeneralRe: Doubts with sorting stl vector... Pin
valikac10-Feb-04 10:07
valikac10-Feb-04 10:07 
GeneralRe: Doubts with sorting stl vector... Pin
Cloaca10-Feb-04 10:18
Cloaca10-Feb-04 10:18 
GeneralRe: Doubts with sorting stl vector... Pin
jhwurmbach11-Feb-04 1:51
jhwurmbach11-Feb-04 1:51 
GeneralRe: Doubts with sorting stl vector... Pin
Cloaca11-Feb-04 6:57
Cloaca11-Feb-04 6:57 
GeneralRe: Doubts with sorting stl vector... Pin
antlers11-Feb-04 11:37
antlers11-Feb-04 11:37 
GeneralRe: Doubts with sorting stl vector... Pin
Cloaca12-Feb-04 4:22
Cloaca12-Feb-04 4:22 
Generalfatal crash on win98 &amp; winMe, Need help. Pin
haritadala10-Feb-04 7:43
haritadala10-Feb-04 7:43 
GeneralRe: fatal crash on win98 &amp; winMe, Need help. Pin
David Crow10-Feb-04 7:49
David Crow10-Feb-04 7:49 
GeneralRe: fatal crash on win98 &amp; winMe, Need help. Pin
haritadala10-Feb-04 8:40
haritadala10-Feb-04 8:40 
GeneralRe: fatal crash on win98 &amp; winMe, Need help. Pin
John R. Shaw10-Feb-04 10:57
John R. Shaw10-Feb-04 10:57 
GeneralRe: fatal crash on win98 &amp; winMe, Need help. Pin
Peter Weyzen10-Feb-04 11:35
Peter Weyzen10-Feb-04 11:35 
GeneralRe: fatal crash on win98 &amp; winMe, Need help. Pin
haritadala10-Feb-04 15:59
haritadala10-Feb-04 15:59 
GeneralRe: fatal crash on win98 &amp; winMe, Need help. Pin
Peter Weyzen10-Feb-04 16:06
Peter Weyzen10-Feb-04 16:06 

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.