【发布时间】:2025-11-29 08:20:02
【问题描述】:
我写了以下课程:
class SomeClass {
private:
void test_function(int a, size_t & b, const int & c) {
b = a + reinterpret_cast<size_t>(&c);
}
public:
SomeClass() {
int a = 17;
size_t b = 0;
int c = 42;
auto test = std::bind(&SomeClass::test_function, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
test(a, b, c);
}
}
就其本身而言,这段代码在 IDE (Visual Studio 2015) 中看起来不错,但是当我尝试编译它时,出现以下错误:
Error C2893 Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)' Basic Server C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\type_traits 1441
Error C2672 'std::invoke': no matching overloaded function found Basic Server C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\type_traits 1441
我做错了什么?
编辑:我也写了这个版本:
class SomeClass {
private:
void test_function(int a, size_t & b, const int & c) {
b = a + reinterpret_cast<size_t>(&c);
}
public:
SomeClass() {
int a = 17;
size_t b = 0;
int c = 42;
auto test = std::bind(&SomeClass::test_function, a, std::placeholders::_1, std::placeholders::_2);
test(b, c);
}
}
我得到完全相同的错误。
【问题讨论】:
-
lambda 版本:
auto test = [this](int a, size_t& b, const int& c) { this->test_function(a, b, c);}