Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not store a call to access data member #10

Closed
2qif49lt opened this issue Apr 3, 2018 · 1 comment
Closed

can not store a call to access data member #10

2qif49lt opened this issue Apr 3, 2018 · 1 comment

Comments

@2qif49lt
Copy link

2qif49lt commented Apr 3, 2018

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;
Naios added a commit that referenced this issue Apr 4, 2018
@Naios Naios closed this as completed in 1e53630 Apr 4, 2018
@Naios
Copy link
Owner

Naios commented Apr 4, 2018

Thanks for your report.
I added the capability to work with class member pointers so this is aligned
to std::function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants