小编rza*_*zan的帖子

使用与std :: function <void()>的unique_ptr参数绑定函数

我正在尝试使以下代码工作:

#include <cstdio>
#include <functional>
#include <string>
#include <memory>

using namespace std;

class Foo {
public:
    Foo(): m_str("foo") { }

    void f1(string s1, string s2, unique_ptr<Foo> p)
        {
            printf("1: %s %s %s\n", s1.c_str(), s2.c_str(), p->str());
        }

    void f2(string s1, string s2, Foo* p)
        {
            printf("2: %s %s %s\n", s1.c_str(), s2.c_str(), p->str());
        }

    const char* str() const { return m_str.c_str(); }

private:
    string m_str;
};

int main()
{
    string arg1 = "arg1";
    string arg2 = "arg2";
    Foo s;
    unique_ptr<Foo> ptr(new Foo); …
Run Code Online (Sandbox Code Playgroud)

c++ c++11

9
推荐指数
2
解决办法
8957
查看次数

标签 统计

c++ ×1

c++11 ×1