Click here to Skip to main content
15,921,716 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
AnswerRe: RTTI option in compiler Pin
User 5838523-Jul-07 17:36
User 5838523-Jul-07 17:36 
AnswerRe: RTTI option in compiler Pin
Rajkumar R3-Jul-07 18:22
Rajkumar R3-Jul-07 18:22 
AnswerRe: RTTI option in compiler Pin
Stephen Hewitt3-Jul-07 18:24
Stephen Hewitt3-Jul-07 18:24 
QuestionA Fast Bresenham Type Algorithm For Drawing Ellipse Pin
KienNT783-Jul-07 17:20
KienNT783-Jul-07 17:20 
AnswerRe: A Fast Bresenham Type Algorithm For Drawing Ellipse Pin
Rajkumar R3-Jul-07 19:22
Rajkumar R3-Jul-07 19:22 
GeneralRe: A Fast Bresenham Type Algorithm For Drawing Ellipse [modified] Pin
KienNT783-Jul-07 20:53
KienNT783-Jul-07 20:53 
Questionmonitoring user connections in my PC Pin
m-a-s-a-k-i-t-o-n3-Jul-07 15:35
m-a-s-a-k-i-t-o-n3-Jul-07 15:35 
QuestionRe: monitoring user connections in my PC Pin
David Crow3-Jul-07 18:10
David Crow3-Jul-07 18:10 
AnswerRe: monitoring user connections in my PC Pin
m-a-s-a-k-i-t-o-n3-Jul-07 22:16
m-a-s-a-k-i-t-o-n3-Jul-07 22:16 
QuestionCustom Vector Allocator Pin
miketra3-Jul-07 10:04
miketra3-Jul-07 10:04 
AnswerRe: Custom Vector Allocator Pin
Maximilien3-Jul-07 10:31
Maximilien3-Jul-07 10:31 
GeneralVector Function erase() Pin
miketra3-Jul-07 10:55
miketra3-Jul-07 10:55 
GeneralRe: Vector Function erase() Pin
Stephen Hewitt3-Jul-07 13:59
Stephen Hewitt3-Jul-07 13:59 
QuestionHow to prevent CMainFrame from restores???? Pin
SandipG 3-Jul-07 9:22
SandipG 3-Jul-07 9:22 
AnswerRe: How to prevent CMainFrame from restores???? Pin
MANISH RASTOGI3-Jul-07 18:46
MANISH RASTOGI3-Jul-07 18:46 

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.