- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello All!
I am using Intel C++ compiler 11.1 for Linux.
How to pass a closure to the function?
For example:
[cpp]class C { void function(TYPE closure); }[/cpp]
What TYPE should I specify, to use the following code:
[cpp]int main(void){ C c; c.function([&](int x,int y){ return x+y; }); return 0; }[/cpp]
Thanks!
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I figured it out!
Something like this:
[cpp]class C{ public: templatevoid function(const CL& closure); }; template void C::function(const CL& closure){ closure(1,2,3); } int main(){ C c; c.function([&](int x,int y,int z){cout << x << y << z ;}); return 0; } [/cpp]

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page