std::bind and function

Started by
3 comments, last by SiCrane 10 years, 11 months ago

#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

An invisible text.
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";}

No, your say function isn't printing anything.

Edit: Got beat to it!

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

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

This topic is closed to new replies.

Advertisement