std::函数参数不完整,不允许使用类型
std::function parameter is incomplete type not allowed
我正试图将lambda分配给std::function
,如下所示:
std::function<void>(thrust::device_vector<float>&) f;
f = [](thrust::device_vector<float> & veh)->void
{
thrust::transform( veh.begin(), veh.end(), veh.begin(), tanh_f() );
};
我得到一个错误:
error: incomplete type is not allowed
error: type name is not allowed
我认为它指的是thrust::device_vector<float>
。我尝试了类型命名和类型定义参数:
typedef typename thrust::device_vector<float> vector;
std::function<void>(vector&) f;
f = [](vector & veh)->void
{
thrust::transform( veh.begin(), veh.end(), veh.begin(), tanh_f() );
};
没有用。然而,如果我只使用lambda(没有std::function
),它就可以工作:
typedef typename thrust::device_vector<float> vector;
auto f = [](vector & veh)->void
{
thrust::transform( veh.begin(), veh.end(), veh.begin(), tanh_f() );
};
我错过了什么?PS:我正在使用nvcc release 6.5, V6.5.12
和g++ (Debian 4.8.4-1) 4.8.4
编译
您使用了错误的语法。
尝试std::function<void(thrust::device_vector<float>&)> f;
而不是
std::function<void(thrust::device_vector<float>&)> f;
声明了一个类型为std::function<void(thrust::device_vector<float>&)>
的变量,它是一个接受thrust::device_vector<float>&
并返回void
的函数对象
g++会给您不完整的类型错误,因为std::function<void>
不是有效的模板实例化。
clang++会给您一个更好的错误消息,告诉您std::function<void>() f;
是一个无效的变量声明:
main.cpp:11:28: error: expected '(' for function-style cast or type construction
std::function<void>(int) f;
~~~^
1 error generated.
相关文章:
- 为什么 c++(g++) 不允许模板返回类型和函数名称之间有空格?
- C++从外部类继承的嵌套类;不允许使用不完整的类型
- E0322:不允许使用抽象类类型 " " 的对象
- 是否允许类类型的 std::function 成员变量(不完整类型)?
- 为什么C++不允许两个同名的函数/类模板,区别仅在于非类型模板参数(整型)的类型?
- 不允许将SDL_Cursor与unique_ptr:error不完整类型一起使用
- HTTP POST 请求不允许我定义上下文类型
- 内建数组出现不允许的类型不完整错误
- 为什么 std::array 的演绎指南不允许不同的类型?
- 为什么标准不允许通过引用捕获不完整的异常类型?
- 数组错误(不允许类型不完整)
- 为什么函数返回类型中不允许参数推导?
- std::function 中不允许引用返回类型吗?
- 类中不允许使用不完整的类型,但在类模板中允许使用不完整的类型
- 为什么协程不允许使用占位符返回类型?
- 错误消息:不允许抽象类类型 "X" 的对象:纯虚拟"Y"没有覆盖器
- 错误:不允许使用抽象类类型的对象
- 如果绝对没有调用成员函数,是否允许使用不完整类型的向量?如果是这样,从什么时候开始
- 错误,不允许类型不完整
- 类构造函数:不允许类型不完整(在成员列表中)-VS C++w/QT