有没有办法将重载的类函数绑定到函数对象?
Is there a way to bind overloaded class functions to a function object?
我是函数绑定概念的新手。我需要基于参数数量的类成员函数重载,我想绑定这些函数。我还有一个疑问,即带有变量参数的函数对象是否可行。
例:
class A{
void print(int i)
{
};
void print(int i,int j){
};
};
//inside the object of A can I create function object like this??
auto f=std::bind(&A::print, this, std::placeholders::_1,...);
在具有精确签名的上下文中,会自动选择适当的重载:
void (A::*p_i)(int) = &A::print;
void (A::*f_ii)(int, int) = &Demo::f;
在无法推断签名的上下文中:
//auto f_a = &A::print; // ambiguous - which one???
您可以使用强制转换显式选择:
auto f_a = static_cast<void (A::*)(int)>(&A::print);
相关文章:
- 传递给 lambda C++绑定函数
- 是否可以将绑定函数存储在容器中?
- C++绑定函数到指针
- 我正在尝试制作一个在 std::bind 之前匹配的网络绑定函数
- 用emscripten中的参考参数绑定函数
- C++-模板函数接受绑定函数作为参数并将其传递给另一个函数
- 将绑定函数分配给 std::函数
- C++中的绑定函数结果
- 绑定函数而不提供参数类型
- std::bind 一个绑定函数
- 创建具有提升绑定/函数的菜单处理程序
- C++绑定函数以用作其他函数的参数
- C++ Boost::bind:指向绑定函数的指针只能用于调用该函数
- 如何指定可能接受 boost::绑定函数的 C++ 函数指针
- 指向绑定函数的指针只能用于调用该函数
- boost::spirit绑定函数,提供参数为spirit:qi::_val
- 套接字绑定函数编译错误
- 在绑定函数/使用lambdas测试消息传递代码时遇到麻烦
- 错误:指向绑定函数的指针只能用于调用该函数
- Windows套接字api绑定函数编译问题