stdbind

    3热度

    1回答

    如果你要绑定到一个功能f一个参考,你可以使用std::bind(f, std::ref(x))。在这种情况下,f需要参考或复印。 现在我有一个功能void g(T & t)。我想将输入参数绑定到std::shared_ptr<T> mySharedPtr,如下所示:std::bind(g, mySharedPtr)。这将保证mySharedPtr的数据至少和绑定一样长。但是由于g需要参考,所以这不

    0热度

    1回答

    我有一个抽象的基类,需要传递给它的构造函数初始化其成员的一些对象。但我想摆脱通过派生类构造函数传递这些对象。 class Derived : public Base { public: Derived(type one, type two, type three) : Base(one, two, three) { // ... 传递给基类的对象与所有创建的

    1热度

    1回答

    我想创建一个父类的版本的虚拟和重载函数的一个std ::函数对象,请看下面的例子: #include <iostream> #include <functional> class Parent { public: virtual void func1() { std::cout << "Parent::func1\n"; }

    19热度

    2回答

    我有以下代码: #include <stdio.h> #include <functional> template <typename T> auto callback(T&& func) ->decltype(func()) { return func(); } double test(double& value) { value=value+1.0;

    1热度

    2回答

    功能时,当我这样做,我得到这个错误 运行时检查失败#0 - ESP的值没有正确跨功能保存 呼叫。这通常是因为调用一个 函数声明一个调用约定,函数指针 以不同的调用约定声明。 当致电dutyStack[0]();。但是,如果我添加dutyStack.reserve(10);或者只有矢量中的一个元素,我不会收到错误。我怀疑是在调整矢量大小时复制元素时发生了什么,但我真的不知道。 #include "s

    0热度

    1回答

    我有一个功能void f (void*, int);,用作回调函数。来电者预计void (*)(int)。我可以使用std::bind1st将一个转换为另一个吗?有没有办法做到这一点,而不使用C++ 11 std::bind,只是std::bind1st?

    0热度

    1回答

    #include <stdio.h> #include <functional> void foo(int a, int b) { printf("%d %d\n", a, b); } int main() { using namespace std::placeholders; auto f1 = std::bind(foo, 10, _1); //

    2热度

    1回答

    我最近遇到这种使用for_each: std::for_each(ts.begin(), ts.end(), [=](T& t){t *= f;}); 好,它的工作原理。对于Ts和T f的容器,这将每个值乘以f。但是我不喜欢这里使用lambda。它很短,但在我看来它只是重复了std::multiplies。此外,它不应该是for_each,而是transform,以表达修改的意图。 但是,st

    1热度

    1回答

    我有,我不能绑定此模板成员函数一个奇怪的问题, 所有这些代码编译:http://ideone.com/wl5hS8 这是一个简单的代码:我有一个ExecutionList应持有可调用的函数在std::vector。我现在可以通过调用ExecutionList::addFunctor来添加功能。但在那里,我不能绑定到template<typename T> void Functor::calcula

    1热度

    1回答

    给定两个explicit构造函数重载(根据不同std::function<...>类型)的std::bind返回值是能够选择要么(从而使呼叫暧昧) call of overloaded ‘Bar(std::_Bind_helper<false, void (Foo::*)(int), Foo*, int>::type)’ is ambiguous 如果我注释掉了,那么代码会编译! 我