So having:
struct A { void foo(int) { } };
typedef std::function<void(int)> 开发者_JAVA技巧Function;
typedef std::vector<Function> FunctionSequence;
typedef FunctionSequence::iterator FunctionIterator;
FunctionSequence funcs;
A a;
funcs.push_back(std::bind(&A::foo, &a, std::placeholders::_1));
funcs.push_back(std::bind(&B::bar, &b, std::placeholders::_1));
// this calls a.foo(42) then b.bar(42):
for (FunctionIterator it(funcs.begin()); it != funcs.end(); ++it)
(*it)(42);
If we were inside class A subscribing funcs.push_back would we say instead of &a this
If I understood correctly your question, the answer should be yes. &variable is always equal to this as seen by the instance methods called over variable.
yes, it sounds logical, but it's just a guess.
subscribing from inside A, would you like to store callback to this particular instance of A. If yes then you need this.
we don't know your needs, and I can imagine cases where all three variants (&a, &b or this) are correct.
加载中,请稍侯......
精彩评论