[英]const pointer as std::bind parameter
以下代码
#include <functional>
#include <iostream>
using namespace std;
struct TestStruct {
int c;
};
int f(int a, int b, const TestStruct **t) { return a + b + (*t)->c; }
void main() {
TestStruct *t;
bind(&f, 1, 2, &t)();
}
报告这个错误
error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
note: With the following template arguments:
note: '_Callable=int (__cdecl *&)(int,int,const TestStruct **)'
note: '_Types={int &, int &, TestStruct **&}'
似乎问题在于const TestStruct**
参数的const TestStruct**
。 但是, const TestStruct *
和TestStruct**
都没有问题。 为什么 ?
您的问题不是来自 bind 本身,而是来自将T**
为T const**
是非法的简单事实。
有关原因的解释,请参见http://c-faq.com/ansi/constmismatch.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.