Click here to Skip to main content
15,895,370 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
Questionstd::mem_fun / std::mem_fun1 / for_each / member functions Pin
Malcolm Smart10-Mar-06 3:42
Malcolm Smart10-Mar-06 3:42 
AnswerRe: std::mem_fun / std::mem_fun1 / for_each / member functions Pin
valikac10-Mar-06 7:41
valikac10-Mar-06 7:41 
QuestionRe: std::mem_fun / std::mem_fun1 / for_each / member functions Pin
Malcolm Smart10-Mar-06 21:17
Malcolm Smart10-Mar-06 21:17 
AnswerRe: std::mem_fun / std::mem_fun1 / for_each / member functions Pin
valikac11-Mar-06 13:10
valikac11-Mar-06 13:10 
GeneralRe: std::mem_fun / std::mem_fun1 / for_each / member functions Pin
Malcolm Smart11-Mar-06 22:59
Malcolm Smart11-Mar-06 22:59 
GeneralRe: std::mem_fun / std::mem_fun1 / for_each / member functions Pin
valikac12-Mar-06 6:08
valikac12-Mar-06 6:08 
AnswerRe: std::mem_fun / std::mem_fun1 / for_each / member functions Pin
valikac10-Mar-06 7:43
valikac10-Mar-06 7:43 
AnswerRe: std::mem_fun / std::mem_fun1 / for_each / member functions Pin
Lim Bio Liong12-Mar-06 6:03
Lim Bio Liong12-Mar-06 6:03 
Hello Angel1058,

One way you can achieve the use of a member function is to declare a class deriving from std::string :

class MyString : public std::string
{
public :
MyString()
{
}

MyString(const char* pstring) :
std::string(pstring)
{
}

~MyString()
{
}

void DoSomethingWithString()
{
std::cout << c_str() << std::endl;
}
};

Yes, you basically extend the std::string with a public member function named DoSomethingWithString().

Then in myClass::Go(), you use MyString instead of std::string :

void Go()
{
std::set<MyString> myStrings;

myStrings.insert("ABC");
myStrings.insert("DEF");
myStrings.insert("GHI");

std::for_each
(
myStrings.begin(),
myStrings.end(),
mem_fun_ref(&MyString::DoSomethingWithString)
);
}

Yes, you would have seen it by now, use mem_fun_ref() as the predicate for for_each(). Basically, MyString::DoSomethingWithString() wsill be called on each contained object in myStrings (which is a set of MyString objects).

Give it a try.

Best Regards,
Bio.

GeneralRe: std::mem_fun / std::mem_fun1 / for_each / member functions Pin
Malcolm Smart12-Mar-06 6:44
Malcolm Smart12-Mar-06 6:44 
AnswerCurry anyone? Pin
Stephen Hewitt12-Mar-06 18:22
Stephen Hewitt12-Mar-06 18:22 
GeneralMadras Pin
Malcolm Smart12-Mar-06 21:27
Malcolm Smart12-Mar-06 21:27 
GeneralRe: Curry anyone? Pin
Rob Caldecott13-Mar-06 21:15
Rob Caldecott13-Mar-06 21:15 
GeneralRe: Curry anyone? Pin
Stephen Hewitt13-Mar-06 22:00
Stephen Hewitt13-Mar-06 22:00 
GeneralRe: Curry anyone? Pin
Rob Caldecott13-Mar-06 22:35
Rob Caldecott13-Mar-06 22:35 
GeneralBoodt to the recsue! Pin
Rob Caldecott13-Mar-06 22:39
Rob Caldecott13-Mar-06 22:39 
GeneralRe: Boodt to the recsue! Pin
Stephen Hewitt13-Mar-06 22:41
Stephen Hewitt13-Mar-06 22:41 
QuestionPassing information to propretypage Pin
shaohao10-Mar-06 3:20
shaohao10-Mar-06 3:20 
AnswerRe: Passing information to propretypage Pin
Michael Dunn10-Mar-06 6:44
sitebuilderMichael Dunn10-Mar-06 6:44 
QuestionImplementing MDI in an ActiveX control Pin
zulat10-Mar-06 0:02
zulat10-Mar-06 0:02 
Question[Message Deleted] Pin
Igor Mihailov9-Mar-06 10:02
Igor Mihailov9-Mar-06 10:02 
AnswerRe: WTL: Unresolved externals Pin
Jörgen Sigvardsson9-Mar-06 10:33
Jörgen Sigvardsson9-Mar-06 10:33 
GeneralRe: WTL: Unresolved externals Pin
Igor Mihailov9-Mar-06 10:54
Igor Mihailov9-Mar-06 10:54 
QuestionHow to delete/destroy modeless dlg/sheet Pin
shaohao9-Mar-06 4:33
shaohao9-Mar-06 4:33 
AnswerRe: How to delete/destroy modeless dlg/sheet Pin
Justin Tay9-Mar-06 7:28
Justin Tay9-Mar-06 7:28 
GeneralRe: How to delete/destroy modeless dlg/sheet Pin
shaohao10-Mar-06 1:35
shaohao10-Mar-06 1:35 

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.