• Advertisement
Sign in to follow this  

std::bind and function

This topic is 1699 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#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

Share this post


Link to post
Share on other sites
Advertisement
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";}

Share this post


Link to post
Share on other sites
You can form a valid C++ statement by placing a semi-colon after an expression. A string literal is a expression.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement