首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将std::ref()用于nvcc时,类没有成员“second_argument_type

将std::ref()用于nvcc时,类没有成员“second_argument_type
EN

Stack Overflow用户
提问于 2016-07-22 17:36:10
回答 1查看 377关注 0票数 0

我试图用cuda 7.5.18和gcc 5.4.0用nvcc编译一个c++文件,但遇到了错误。举个简单的例子:

代码语言:javascript
复制
#include <thrust/functional.h>

struct test_struct {
    //..
}

void f(test_struct& a) {
    //..
}

int main() {
    test_struct a;
    std::function<void()> bound_f = std::bind(f, std::ref(a));
}

使用nvcc -c -std=c++11 test.cu -o test.o编译此代码会导致以下错误输出:

代码语言:javascript
复制
/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/c++/functional(78): error: class "test_struct" has no member "result_type"
          detected during:
            instantiation of class "std::_Maybe_get_result_type<_Functor, void> [with _Functor=test_struct]" 
(86): here
            instantiation of class "std::_Weak_result_type_impl<_Functor> [with _Functor=test_struct]" 
(184): here
            instantiation of class "std::_Weak_result_type<_Functor> [with _Functor=test_struct]" 
(264): here
            instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=test_struct]" 
(283): here
            instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=test_struct]" 
(399): here
            instantiation of class "std::reference_wrapper<_Tp> [with _Tp=test_struct]" 
test.cu(14): here

/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/c++/functional(266): error: class "test_struct" has no member "argument_type"
          detected during:
            instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=test_struct]" 
(283): here
            instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=test_struct]" 
(399): here
            instantiation of class "std::reference_wrapper<_Tp> [with _Tp=test_struct]" 
test.cu(14): here

/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/c++/functional(267): error: class "test_struct" has no member "first_argument_type"
          detected during:
            instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=test_struct]" 
(283): here
            instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=test_struct]" 
(399): here
            instantiation of class "std::reference_wrapper<_Tp> [with _Tp=test_struct]" 
test.cu(14): here

/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/c++/functional(268): error: class "test_struct" has no member "second_argument_type"
          detected during:
            instantiation of class "std::_Reference_wrapper_base_impl<true, true, _Tp> [with _Tp=test_struct]" 
(283): here
            instantiation of class "std::_Reference_wrapper_base<_Tp> [with _Tp=test_struct]" 
(399): here
            instantiation of class "std::reference_wrapper<_Tp> [with _Tp=test_struct]" 
test.cu(14): here

5 errors detected in the compilation of "/tmp/tmpxft_00003b29_00000000-7_test.cpp1.ii".

我找不到任何与error: ... has no member "second_argument_type"等行相关的nvcc,所以我完全一无所知。显然,不知何故找不到std::function的类成员(参见here)。

我能做些什么来解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2016-07-22 17:52:38

错误的原因尚不清楚,但您可以轻松地使用lambda:

代码语言:javascript
复制
std::function<void()> bound_f = [&a](){ return f(a); };
票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38523067

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档