Click here to Skip to main content
15,925,602 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Text Direction Pin
KarstenK3-Jul-07 21:13
mveKarstenK3-Jul-07 21:13 
GeneralRe: Text Direction Pin
Try3-Jul-07 22:59
Try3-Jul-07 22:59 
AnswerRe: Text Direction Pin
Matthew Faithfull4-Jul-07 4:35
Matthew Faithfull4-Jul-07 4:35 
AnswerRe: Text Direction (Long) Pin
Matthew Faithfull4-Jul-07 23:03
Matthew Faithfull4-Jul-07 23:03 
GeneralRe: Text Direction (Long) Pin
Try4-Jul-07 23:24
Try4-Jul-07 23:24 
QuestionInterview question Pin
tasumisra3-Jul-07 20:06
tasumisra3-Jul-07 20:06 
AnswerRe: Interview question Pin
G Haranadh3-Jul-07 20:27
G Haranadh3-Jul-07 20:27 
GeneralRe: Interview question Pin
tasumisra3-Jul-07 21:25
tasumisra3-Jul-07 21:25 
QuestionCross application process Handle Pin
SNI3-Jul-07 20:05
SNI3-Jul-07 20:05 
AnswerRe: Cross application process Handle Pin
Stephen Hewitt3-Jul-07 20:11
Stephen Hewitt3-Jul-07 20:11 
GeneralRe: Cross application process Handle Pin
SNI3-Jul-07 20:18
SNI3-Jul-07 20:18 
GeneralRe: Cross application process Handle Pin
Stephen Hewitt3-Jul-07 20:21
Stephen Hewitt3-Jul-07 20:21 
GeneralRe: Cross application process Handle Pin
SNI3-Jul-07 20:29
SNI3-Jul-07 20:29 
GeneralRe: Cross application process Handle Pin
Stephen Hewitt3-Jul-07 20:35
Stephen Hewitt3-Jul-07 20:35 
GeneralRe: Cross application process Handle Pin
SNI3-Jul-07 20:44
SNI3-Jul-07 20:44 
GeneralRe: Cross application process Handle Pin
Stephen Hewitt3-Jul-07 20:48
Stephen Hewitt3-Jul-07 20:48 
GeneralRe: Cross application process Handle Pin
SNI3-Jul-07 21:10
SNI3-Jul-07 21:10 
GeneralRe: Cross application process Handle Pin
Naveen3-Jul-07 21:10
Naveen3-Jul-07 21:10 
GeneralRe: Cross application process Handle [modified] Pin
SNI3-Jul-07 23:46
SNI3-Jul-07 23:46 
QuestionFind computers Pin
IMANTHA3-Jul-07 19:38
IMANTHA3-Jul-07 19:38 
AnswerRe: Find computers Pin
Naveen3-Jul-07 20:03
Naveen3-Jul-07 20:03 
QuestionSorting a user class based CArray Pin
al25003-Jul-07 19:31
al25003-Jul-07 19:31 
AnswerRe: Sorting a user class based CArray Pin
Stephen Hewitt3-Jul-07 19:55
Stephen Hewitt3-Jul-07 19:55 
Try something like this. Note I use STL's collection classes and not MFC's.
----------------------------------

// Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

class CMyClass
{
public:
CMyClass(int a, int b)
: m_A(a)
, m_B(b)
{}

int m_A;
double m_B;
};

// Function to sort by 'm_A'.
inline bool MyClassLessByA(const CMyClass &l, const CMyClass &r)
{
return l.m_A < r.m_A;
}

// Function to sort by 'm_B'.
inline bool MyClassLessByB(const CMyClass &l, const CMyClass &r)
{
return l.m_B < r.m_B;
}

// Function to write the class to an output stream.
inline std::ostream& operator<<(std::ostream &os, const CMyClass &cr)
{
os << "CMyClass(" << cr.m_A << ", " << cr.m_B << ")";
return os;
}

int main(int arvc, char* argv[])
{
using namespace std;

// Create an "array" and populate it.
vector<CMyClass> array;
array.push_back(CMyClass(1, 5.0));
array.push_back(CMyClass(2, 4.0));
array.push_back(CMyClass(3, 3.0));
array.push_back(CMyClass(4, 2.0));
array.push_back(CMyClass(5, 1.0));

// Shuffle the array into a random order.
random_shuffle(array.begin(), array.end());

// Output the shuffled array to the console.
cout << "Array before sorting:" << endl;
copy(array.begin(), array.end(), ostream_iterator<CMyClass>(cout, "\n"));
cout << endl;

// Sort by 'm_A'.
sort(array.begin(), array.end(), MyClassLessByA);

// Output the array to the console.
cout << "Sorted by 'm_A':" << endl;
copy(array.begin(), array.end(), ostream_iterator<CMyClass>(cout, "\n"));
cout << endl;

// Sort by 'm_B'.
sort(array.begin(), array.end(), MyClassLessByB);

// Output the array to the console.
cout << "Sorted by 'm_B':" << endl;
copy(array.begin(), array.end(), ostream_iterator<CMyClass>(cout, "\n"));
cout << endl;

return 0;
}

----------------------------------

The output on my system was the following:

Array before sorting:
CMyClass(5, 1)
CMyClass(4, 2)
CMyClass(1, 5)
CMyClass(3, 3)
CMyClass(2, 4)

Sorted by 'm_A':
CMyClass(1, 5)
CMyClass(2, 4)
CMyClass(3, 3)
CMyClass(4, 2)
CMyClass(5, 1)

Sorted by 'm_B':
CMyClass(5, 1)
CMyClass(4, 2)
CMyClass(3, 3)
CMyClass(2, 4)
CMyClass(1, 5)


Steve

QuestionMy registered activex control is corrupted or missing. Pin
adityarao313-Jul-07 18:35
adityarao313-Jul-07 18:35 
QuestionRTTI option in compiler Pin
vibindia3-Jul-07 17:30
vibindia3-Jul-07 17:30 

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.