#include <iostream>
using namespace std;
class Tmp1 {
public:
int foo() {
cout << "Tmp1.foo" << endl;
return ret;
}
string walk() {
cout << "walk" << endl;
return "cout walk";
}
int ret = 1;
};
class Tmp2 {
public:
int foo() {
cout << "Tmp2.foo" << endl;
return ret;
}
string run() {
cout << "run" << endl;
return "cout run";
}
int ret = 2;
};
struct OutPara {
int ret = 0;
string desc;
};
template<typename T, typename F>
void print(T t, const F &f) {
cout << "test" << endl;
f(t);
}
int main()
{
Tmp1 t1;
OutPara out;
print(t1, [&](Tmp1 &t)->void{
out.desc = t.walk();
out.ret = t.foo();
});
cout << out.ret << "\t" << out.desc << endl;
Tmp2 t2;
print(t2, [&](Tmp2 &t)->void{
out.desc = t.run();
out.ret = t.foo();
});
cout << out.ret << "\t" << out.desc << endl;
return 0;
}
The output
test
walk
Tmp1.foo
1 cout walk
test
run
Tmp2.foo
2 cout run
Read More:
- How to Fix Warning: Statement lambda can be replaced with expression lambda
- JAVA lambda Syntax error on tokens, Expression expected instead
- How to use C + + function pointer array
- C / C + + rounding function: round function
- Error: (44,73) lambda expression and XML are not supported in Java: – source 1.7 Error:java : Compilation failed
- C / C + + rounding function ceil(), floor ()
- [C + +] G + + compiler class template error message: template argument 1 is invalid
- C++:error C2228: left of ‘.str’ must have class/struct/union
- error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
- High precision addition function template
- C / C + + library function (tower / tower) realizes the conversion of letter case
- C + + common errors: “error: XXX in namespace ‘STD’ does not name a template type”
- [C + +] C + + overload operator = must be a nonstatic member function?
- template with C linkage
- error: invalid use of non-static member function
- C code compilation_ Error: expected expression before ‘Int’
- An error happened during template parsing (template: “class path resource
- Vue report failed to mount component: template or render function not defined
- C++ cin.ignore Use of ()
- error Expected an assignment or function call and instead saw an expression