[英]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.