Skip to content

Commit

Permalink
2021-05-23 18:21:29 CST W21D0
Browse files Browse the repository at this point in the history
  • Loading branch information
aggresss committed May 23, 2021
1 parent 4280801 commit 2d65e0e
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions workbench/functor/functor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

typedef int (*AddFunc)(int, int);

int Add(int a, int b, AddFunc addFunc) {
template <typename T>
int Add(int a, int b, T addFunc) {
return addFunc(a, b);
}

Expand All @@ -18,12 +19,8 @@ class AddCls {
}
};

int addProxy(int a, int b) {
return AddCls().operator()(a, b);
}

int main() {
std::cout << Add(1, 2, addImpl) << std::endl;
std::cout << Add(1, 2, addProxy) << std::endl;
std::cout << Add(1, 2, AddCls()) << std::endl;
return 0;
}

0 comments on commit 2d65e0e

Please sign in to comment.