Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

std::bind and function

4: Adsense

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   

663
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.

#2 Wooh   Members   

1088
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   GDNet+   

4313
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   

663
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   

11769
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.