我是函数绑定概念的新手。我需要根据参数数量重载类成员函数,并且我想绑定这些函数。我还不确定是否可以使用带有可变参数的函数对象。
示例:
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);