void fun(int a)
{
cout << "fun" << endl;
}
void add(int a, int b)
{
cout << "add" << endl;
}
template<typename T, typename ...Ty>
class myfunction
{
};
template<typename T, typename ...Ty>
class myfunction<T(Ty...)>
{
public:
using PFUN = T(*)(Ty...);
myfunction(PFUN pf) :pfunc(pf) { cout << "构造" << endl; }
T operator()(Ty... ty)
{
cout << "()" << endl;
return pfunc(ty ...);
}
private:
PFUN pfunc;
};
int main()
{
cout << "start" << endl;
myfunction<void(int)>func = fun;
func(1);
myfunction<void(int, int)>fund = add;
fund(1,2);
cout << "end" << endl;
}
// 定义日志打印宏
#define LOG(fmt, ...) printf("[%s:%s:%d] " fmt "\n", __FILE__, __func__, __LINE__, ##__VA_ARGS__)
void foo() {
LOG("Inside foo");
}
void bar() {
LOG("Inside bar");
}
int main() {
LOG("Inside main");
foo();
bar();
return 0;
}
文章评论