Skip to content

can not store a call to access data member #10

@2qif49lt

Description

@2qif49lt
struct Foo {
    Foo(int num) : num_(num) {}
    void print_add(int i) const { std::cout << num_+i << '\n'; }
    int num_;
};

   const Foo foo1(1);
//   fu2::function<int(const Foo&)> fn3 = &Foo::num_; // report fail here
    std::function<int(const Foo&)> stdfn3 = &Foo::num_;

    std::cout << stdfn3(2) << std::endl;
    std::cout << stdfn3(foo1) << std::endl;

error: conversion from 'int Foo::*' to non-scalar type....
gcc version 6.3.0 (GCC)

but it worked with std::bind

fu2::function<int(const Foo&)> fn5 = std::bind(&Foo::num_, _1); // this is ok
    cout << fn5(foo1) << endl;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions