Jump to content
  • Advertisement
Sign in to follow this  
lride

std::bind and function

This topic is 2024 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

No, your say function isn't printing anything.

 

Edit: Got beat to it!

Edited by Mussi

Share this post


Link to post
Share on other sites

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

Edited by lride

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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!