Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 常量指针作为std::bind参数_C++_Stdbind - Fatal编程技术网

C++ 常量指针作为std::bind参数

C++ 常量指针作为std::bind参数,c++,stdbind,C++,Stdbind,下面的代码 #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)

下面的代码

#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)();
}

问题似乎是
const TestStruct**
param的常量。但是,
const TestStruct*
TestStruct**
都没有问题。为什么?

您的问题不是来自绑定本身,而是来自一个简单的事实,即将
T**
强制转换为
T const**
是非法的


有关原因的解释,请参阅。

您的问题不是来自绑定本身,而是来自一个简单的事实,即将
T**
强制转换为
T const**
是非法的


有关原因的解释,请参见。

您是否打算编写
TestStruct**const
?@LightnessRacesinOrbit No。我已经简化了
f
函数,它是一个外部
C
函数,我想绑定到它,它的签名就是这样。您不能。顺便问一下:
main
返回
int
,而不是
void
。您是否打算编写
TestStruct**const
?@LightnessRacesinOrbit否。我已经简化了,
f
函数是一个我想要绑定到的外部
C
函数,它的签名是这样的。您不能。顺便说一下:
main
返回
int
,而不是
void
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 **&}'