0
struct Test {
    int parameter(int) { return 0; }
    int nonparameter() { return 0; }
    void package() {
        std::function<int()> pp = std::bind(&Test::nonparameter, this);
        // std::function<int(int)> np = std::bind(&Test::parameter, this);
    }
};

I was doing some function classification jobs in visual stuido, when I need to do something like the upper code saying, something strange behavior confused me so much that the comment line can not be compiled, am I missing some important concept. Any answer will be appreciated.
environment : visual studio professional 2022

degawong
  • 49
  • 6
  • 3
    https://en.cppreference.com/w/cpp/utility/functional/placeholders – Alan Birtles Nov 15 '22 at 08:03
  • Simplest answer is don't use `std::bind` use lambda functions. `std::function np = [this](int i) { return parameter(i); }` – john Nov 15 '22 at 08:04
  • looking up for my previous notes, the code `std::function np = std::bind(&Test::parameter, this, std::placeholders::_1);` like this can be compiled. – degawong Nov 15 '22 at 08:07

0 Answers0