![]() |
| | #16 |
| Guest Join Date: Aug 2001
Posts: 4,923
| What, you expect me to actually read the code? ![]() >> I'm just concerned about returning void from the FncPtr call. Code: template < typename R >
R foo( R ( *f )( ) )
{
return f( );
}
int bar( void )
{
return 3114;
}
void qux( void )
{ }
int main( void )
{
cout << foo( bar ) << endl;
foo( qux );
return 0;
}
|
| Sebastiani is offline | |
| | #17 | ||
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Quote:
So this actually compiles, where you try to return "void"?
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| ||
| Elysia is offline | |
| | #18 |
| Guest Join Date: Aug 2001
Posts: 4,923
| >> Aww, come on. It's not that big and complicated. Oh I know, I should have paid closer attention. >> So this actually compiles, where you try to return "void"? Yep. As long as you don't try to explicitly declare a variable of that type, though (which is really too bad because that would have been a useful feature). So in other words, this would not compile if used with void: Code: template < typename R >
R foo( R ( *f )( ) )
{
R r = f( );
return r;
}
|
| Sebastiani is offline | |
| | #19 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Alright, cool, no worries about that then.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #20 | |
| Registered User Join Date: Jul 2009
Posts: 11
| Quote:
And, I cant see but when I am compiling that, its returning a error: Code: In function ‘void example2(Class_t&, Fnc_t) [with Class_t = ExClass, Fnc_t = int (ExClass::*)(const int&)]’: 16: instantiated from here 10: error: too few arguments to function | |
| tharnier is offline | |
| | #21 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Ah, that's because the function takes an int, but we don't pass one. You can fix it like: (Class.*FncPtr)(10); func(10);
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #22 | |
| Registered User Join Date: Jul 2009
Posts: 11
| Quote:
But I'm trying to use boost::function... Do you know some really good book to indicate to me??? with this kind of doubt | |
| tharnier is offline | |
| | #23 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Oh? Then let's borrow the power of boost::bind a little more: example( boost::bind(&ExClass::func, f, 10) ); Notice that I put a number in there as well. Now func(); Simply will work. Praised be boost!
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #24 |
| Registered User Join Date: Jul 2009
Posts: 11
| What probably will solve my problem is: Code: ExClass f; f.func = boost::bind( &ExClass::func, &f ); example( f.func ); But, do I really need to install all boost library to use boost::bind()??? |
| tharnier is offline | |
| | #25 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| It doesn't work that way! Just pass what boost::bind returns directly to your function. You need to download the boost package, yes, but you don't need to install any dlls to use it. However, you can't just break it into pieces since it has dependencies on other headers in the boost distribution. Code: ExClass f; example( boost::bind(&ExClass::func, f, 1000) );
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #26 | |
| Registered User Join Date: Jul 2009
Posts: 11
| Quote:
Can you suggest one?? To look up that kind of doubt? | |
| tharnier is offline | |
| | #27 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Not much about boost, sadly. There is one book about boost, I think. Can't remember its name. It's somewhat old and doesn't cover that much, but it's about the only one available or so. A search on the web should reveal more information about that. Otherwise the boost homepage is your best source of information.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #28 | |
| Registered User Join Date: Jul 2009
Posts: 11
| Quote:
| |
| tharnier is offline | |
| | #29 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Oh, okay. Then check the books thread. If you haven't checked out Accelerated C++, then you should probably do that too. It doesn't cover just the basics; it covers a lot of more and a lot of it is handy stuff!
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #30 |
| Registered User Join Date: Jul 2009
Posts: 11
| Ok, thank you all your attention and patient to my problem!!!! |
| tharnier is offline | |
![]() |
| Tags |
| argument, function, overloaded, reference, type |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing A Function Into A Constructor | fourplay | C++ Programming | 6 | 03-15-2009 06:06 AM |
| Compiling sample DarkGDK Program | Phyxashun | Game Programming | 6 | 01-27-2009 03:07 AM |
| Passing function as argument | NeMewSys | C Programming | 16 | 06-11-2008 02:03 PM |
| passing a function as an argument | angelscars | C++ Programming | 6 | 12-06-2005 09:53 PM |
| Didn't quite know where to post this.......compiler problem... | incognito | C++ Programming | 5 | 02-08-2003 07:42 PM |