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

ATL / WTL / STL

 
GeneralRe: Using find_if with vector of pointers ? Pin
Stephen Hewitt13-Mar-06 11:34
Stephen Hewitt13-Mar-06 11:34 
GeneralRe: Using find_if with vector of pointers ? Pin
squidev13-Mar-06 7:39
squidev13-Mar-06 7:39 
AnswerRe: Using find_if with vector of pointers ? Pin
Axter18-Mar-06 12:43
professionalAxter18-Mar-06 12:43 
Questionsaving drawings Pin
_tasleem10-Mar-06 23:05
_tasleem10-Mar-06 23:05 
QuestionHow to pass dialog's WM_CONTEXTMENU to child? Pin
Light Walker10-Mar-06 3:42
Light Walker10-Mar-06 3:42 
AnswerRe: How to pass dialog's WM_CONTEXTMENU to child? Pin
Igor Vigdorchik12-Mar-06 8:42
Igor Vigdorchik12-Mar-06 8:42 
GeneralRe: How to pass dialog's WM_CONTEXTMENU to child? Pin
Light Walker13-Mar-06 13:28
Light Walker13-Mar-06 13:28 
Questionstd::mem_fun / std::mem_fun1 / for_each / member functions Pin
Malcolm Smart10-Mar-06 3:42
Malcolm Smart10-Mar-06 3:42 
Hi
I want to pass a member function to the std::for_each algorithm but strguggling. I've seen where you can use std::mem_fun to bind a member function of the 'contained' class, but I want a member function of a different class...code below shows what I want to do and code after that shows my work around.

I could use a for..next loop, but don't think I should when these algorithms are so d*** neat!

What I want to do....

class myClass
{
//assume ctors etc are good - no tricks here!!

private:
	void DoSomethingWithString( std::string *pString );
public:
	void Go()
	{
		std::set <std::string > myStrings;
		myStrings.insert("ABC");
		myStrings.insert("DEF");
		myStrings.insert("GHI");

		std::for_each(myStrings.begin() , myStrings.end() , /* correct format for calling 'DoSomethingWithString */ );
	}
};

//I've tried   std::bind1st( std::mem_fun(&myClass::DoSomethingWithString) , this) , binding this to the member function but no joy.....


and a work around....

class myClass
{
	class DoStringThing
		{
		private:
			myClass* m_class;
		public:
			DoStringThing( myClass* class_param) : m_class( class_param)
			{
			}
	
			void operator()( std::string &filename)
			{
				m_class->DoSomethingWithString( &filename );
			}
		
		};
	friend class DoStringThing;

private:
	void DoSomethingWithString( std::string *pString );
public:
	void Go()
	{
		std::set <std::string> myStrings;
		myStrings.insert("ABC");
		myStrings.insert("DEF");
		myStrings.insert("GHI");

		std::for_each(myStrings.begin() , myStrings.end() , DoStringThing(this) );
	}
};


So, how can I call a member of the class that is executing the for_each...?


Regards

Rose | [Rose] Angel Rose | [Rose]

*********************************************
The sooner you fall behind, the longer you have to catch up.
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 
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 

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.