Click here to Skip to main content
15,899,937 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Can't make a hash_map with std::string for key Pin
ZoogieZork24-Jun-03 14:28
ZoogieZork24-Jun-03 14:28 
GeneralRe: Can't make a hash_map with std::string for key Pin
Stuart Dootson24-Jun-03 21:06
professionalStuart Dootson24-Jun-03 21:06 
GeneralRe: Can't make a hash_map with std::string for key Pin
Alexandru Savescu27-Jun-03 1:51
Alexandru Savescu27-Jun-03 1:51 
GeneralThanks for the help Pin
Jonathan Gilligan27-Jun-03 4:45
Jonathan Gilligan27-Jun-03 4:45 
GeneralProperty Sheets, Help button access from an IPropertyPageImpl Pin
Debs24-Jun-03 1:15
Debs24-Jun-03 1:15 
GeneralIWebBrowser2/IWebBrowserApp problem Pin
peterhe23-Jun-03 11:50
peterhe23-Jun-03 11:50 
Generalvector.sort() Pin
Greg142122-Jun-03 11:24
sussGreg142122-Jun-03 11:24 
GeneralRe: vector.sort() Pin
Andrew Walker22-Jun-03 16:55
Andrew Walker22-Jun-03 16:55 
Greg1421 wrote:
cats.sort() by cats.get_age().

Vectors don't have a sort method, but lists do. To compensate you will need to use the generic STL sort algorithm.

Greg1421 wrote:
return &a.get_age < &b.get_age;

The predicate should call cat::get_age() rather than taking its address.

Make sure that cats::get_age() is declared const, if it isn't the predicate won't compile.

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class cat
{
public:
	cat(int age)
		: age_(age)
	{
	}

	int get_age() const { return age_; }

private:
	int age_;
};

bool apredicate(const cat& a, const cat& b)
{
return a.get_age() < b.get_age();
}

int main()
{
	vector<cat> v;
	v.push_back(cat(0));
	v.push_back(cat(2));
	v.push_back(cat(1));
	v.push_back(cat(4));
	v.push_back(cat(3));
	v.push_back(cat(9));
	sort(v.begin(),v.end(),apredicate);
	for(int i = 0; i < v.size(); i++)
	{
		cout << v.at(i).get_age() << endl;
	}
	return 0;
}



If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.

Rudyard Kipling

QuestionHow can ActiveX control with no input focus respond to keyboard event? Pin
stanley guan22-Jun-03 2:42
stanley guan22-Jun-03 2:42 
GeneralChanging a CAxDialogImpl dialog title bar caption Pin
Captain Apathy20-Jun-03 10:12
Captain Apathy20-Jun-03 10:12 
GeneralRe: Changing a CAxDialogImpl dialog title bar caption Pin
Michael Dunn20-Jun-03 18:19
sitebuilderMichael Dunn20-Jun-03 18:19 
GeneralRe: Changing a CAxDialogImpl dialog title bar caption Pin
Captain Apathy23-Jun-03 5:13
Captain Apathy23-Jun-03 5:13 
Generaloptional keyword Pin
SoloVision19-Jun-03 21:45
SoloVision19-Jun-03 21:45 
GeneralRe: optional keyword Pin
AlexO20-Jun-03 6:17
AlexO20-Jun-03 6:17 
Generaloptional keyword Pin
SoloVision19-Jun-03 21:44
SoloVision19-Jun-03 21:44 
General'optional' keyword Pin
SoloVision19-Jun-03 21:43
SoloVision19-Jun-03 21:43 
GeneralICollectionOnSTLImpl and how to use it in an MFC client App Pin
Braulio Dez19-Jun-03 0:59
Braulio Dez19-Jun-03 0:59 
QuestionWhat these words mean? Pin
Thomas Lau15-Jun-03 23:14
Thomas Lau15-Jun-03 23:14 
AnswerRe: What these words mean? Pin
Thomas Lau15-Jun-03 23:22
Thomas Lau15-Jun-03 23:22 
AnswerRe: What these words mean? Pin
Michael P Butler15-Jun-03 23:31
Michael P Butler15-Jun-03 23:31 
GeneralRe: What these words mean? Pin
Thomas Lau15-Jun-03 23:36
Thomas Lau15-Jun-03 23:36 
QuestionHow to add special inform to registry for my control? Pin
Thomas Lau15-Jun-03 23:06
Thomas Lau15-Jun-03 23:06 
AnswerRe: How to add special inform to registry for my control? Pin
AlexO16-Jun-03 10:29
AlexO16-Jun-03 10:29 
QuestionATL Object Wizard got lost??? Pin
Dominik Reichl14-Jun-03 22:37
Dominik Reichl14-Jun-03 22:37 
AnswerRe: ATL Object Wizard got lost??? Pin
Thomas Lau15-Jun-03 23:10
Thomas Lau15-Jun-03 23:10 

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.