Jump to content

  • Log In with Google      Sign In   
  • Create Account

std::bind and function


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 lride   Members   -  Reputation: 633

Like
0Likes
Like

Posted 27 May 2013 - 05:04 PM

#include <iostream>
#include <functional>

class Foo
{
public:
	int a;
	void say(){"I'm foo\n";}
};

class FooManager
{
public:
	void takeFoo(Foo *f){f->say();}
};

int main()
{
	FooManager mf;
	std::function<void()> func=std::bind(&FooManager::takeFoo, &mf, new Foo);
	func();
	std::cin.get();
}

Isn't this supposed to print "I'm foo"?

It's not doing anything


Edited by lride, 27 May 2013 - 05:42 PM.

An invisible text.

Sponsor:

#2 Wooh   Members   -  Reputation: 653

Like
3Likes
Like

Posted 27 May 2013 - 05:24 PM

The say function doesn't do anything. Use std::cout if you want to print the string.
void say(){std::cout<<"I'm foo\n";}


#3 Mussi   Crossbones+   -  Reputation: 2107

Like
2Likes
Like

Posted 27 May 2013 - 05:28 PM

No, your say function isn't printing anything.

 

Edit: Got beat to it!


Edited by Mussi, 27 May 2013 - 05:29 PM.


#4 lride   Members   -  Reputation: 633

Like
0Likes
Like

Posted 27 May 2013 - 05:39 PM

Im so dumb... but how would that even compile...?


Edited by lride, 27 May 2013 - 05:40 PM.

An invisible text.

#5 SiCrane   Moderators   -  Reputation: 9676

Like
2Likes
Like

Posted 27 May 2013 - 06:20 PM

You can form a valid C++ statement by placing a semi-colon after an expression. A string literal is a expression.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS