从gcc 5.4升级至gcc 6.3 std::thread std:ref issue



我最近从gcc 5.4升级到了gcc 6.3。过去编译和运行得很好的C++代码停止了编译,我没有足够的经验来推断出哪里出了问题。

代码在我创建的一个对象中,该对象用于使用sfml生成窗口。它实例化了一个线程,该线程使用sfml::Window指针根据外部设置的指向视频帧的指针更新图像。

代码是基本而简单的,我在代码的其他地方生成线程(尽管不是对象的线程)。

以下是代码片段:

class owindow
{
public:
...
private:
...
std::thread renderThread;
...
void windowRender(void);
...
};
owindow::owindow(std::string name, win_t type, int width, int height, uint32_t *image)
: renderThread()
{
typ = type;
wid = width;
hei = height;
nam = name;
frame = image;
resizewin = false;
killthread = false;
...
window = new sf::Window(sf::VideoMode(windowwidth, windowheight), name.c_str(), sf::Style::Default, settings);
window->setVerticalSyncEnabled(false);
...
void owindow::start(void)
{
// Start the render thread.
renderThread = std::thread(&owindow::windowRender, this);
}

上面显示的renderThread=行(错误输出中的第174行)上生成的错误是漫长而残酷的,老实说,当我试图理解它们时,我觉得自己快要淹死了。c++什么时候有元组了?哈哈,我在工作中学习python,终于明白了元组是什么,然后我就发生了。。。

我刚刚检查过,它仍然使用gcc 5.4编译和运行。

以下是错误,注意这只是最初的几个错误,我不想在论坛上发垃圾邮件。

更新:

/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple: In instantiation of 'static constexpr bool std::_TC<<anonymous>, _Elements>::_MoveConstructibleTuple() [with _UElements = {const std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&}; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]':
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:626:248:   required by substitution of 'template<class ... _UElements, typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (5ul >= 1)), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {const std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&}; typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (5ul >= 1)), bool>::type <anonymous> = <missing>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/functional:1363:8:   required from 'struct std::_Bind_simple<void (*(int, camera*, int*, int*))(int, camera*, int*, int*)>'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/thread:136:55:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(int, camera*, int*, int*); _Args = {int&, camera*, int*&, int*&}]'
/...snip.../ofunctions.hpp:3221:97:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:483:67: error: mismatched argument pack lengths while expanding 'std::is_constructible<_Elements, _UElements&&>'
return __and_<is_constructible<_Elements, _UElements&&>...>::value;
^~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:484:1: error: body of constexpr function 'static constexpr bool std::_TC<<anonymous>, _Elements>::_MoveConstructibleTuple() [with _UElements = {const std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&}; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]' not a return-statement
}
^
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple: In instantiation of 'static constexpr bool std::_TC<<anonymous>, _Elements>::_ImplicitlyMoveConvertibleTuple() [with _UElements = {const std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&}; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]':
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:626:362:   required by substitution of 'template<class ... _UElements, typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (5ul >= 1)), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {const std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&}; typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (5ul >= 1)), bool>::type <anonymous> = <missing>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/functional:1363:8:   required from 'struct std::_Bind_simple<void (*(int, camera*, int*, int*))(int, camera*, int*, int*)>'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/thread:136:55:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(int, camera*, int*, int*); _Args = {int&, camera*, int*&, int*&}]'
/...snip.../ofunctions.hpp:3221:97:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:489:65: error: mismatched argument pack lengths while expanding 'std::is_convertible<_UElements&&, _Elements>'
return __and_<is_convertible<_UElements&&, _Elements>...>::value;
^~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:490:1: error: body of constexpr function 'static constexpr bool std::_TC<<anonymous>, _Elements>::_ImplicitlyMoveConvertibleTuple() [with _UElements = {const std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&}; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]' not a return-statement
}
^
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple: In instantiation of 'static constexpr bool std::_TC<<anonymous>, _Elements>::_NonNestedTuple() [with _SrcTuple = const std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]':
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:662:419:   required by substitution of 'template<class ... _UElements, class _Dummy, typename std::enable_if<((std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ConstructibleTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyConvertibleTuple<_UElements ...>()) && std::_TC<(std::is_same<_Dummy, void>::value && (1ul == 1)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NonNestedTuple<const tuple<_Elements ...>&>()), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(const std::tuple<_Args1 ...>&) [with _UElements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}; _Dummy = void; typename std::enable_if<((std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ConstructibleTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyConvertibleTuple<_UElements ...>()) && std::_TC<(std::is_same<_Dummy, void>::value && (1ul == 1)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NonNestedTuple<const tuple<_Elements ...>&>()), bool>::type <anonymous> = <missing>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/functional:1363:8:   required from 'struct std::_Bind_simple<void (*(int, camera*, int*, int*))(int, camera*, int*, int*)>'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/thread:136:55:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(int, camera*, int*, int*); _Args = {int&, camera*, int*&, int*&}]'
/...snip.../ofunctions.hpp:3221:97:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:495:244: error: wrong number of template arguments (6, should be 2)
return  __and_<__not_<is_same<tuple<_Elements...>,
                                                                                                                                                                              ^    
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/type_traits:1558:8: note: provided for 'template<class _From, class _To> struct std::is_convertible'
struct is_convertible
^~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:502:1: error: body of constexpr function 'static constexpr bool std::_TC<<anonymous>, _Elements>::_NonNestedTuple() [with _SrcTuple = const std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]' not a return-statement
}
^
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple: In instantiation of 'static constexpr bool std::_TC<<anonymous>, _Elements>::_MoveConstructibleTuple() [with _UElements = {std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>}; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]':
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:626:248:   required by substitution of 'template<class ... _UElements, typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (5ul >= 1)), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>}; typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (5ul >= 1)), bool>::type <anonymous> = <missing>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/functional:1363:8:   required from 'struct std::_Bind_simple<void (*(int, camera*, int*, int*))(int, camera*, int*, int*)>'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/thread:136:55:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(int, camera*, int*, int*); _Args = {int&, camera*, int*&, int*&}]'
/...snip.../ofunctions.hpp:3221:97:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:483:67: error: mismatched argument pack lengths while expanding 'std::is_constructible<_Elements, _UElements&&>'
return __and_<is_constructible<_Elements, _UElements&&>...>::value;
^~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:484:1: error: body of constexpr function 'static constexpr bool std::_TC<<anonymous>, _Elements>::_MoveConstructibleTuple() [with _UElements = {std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>}; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]' not a return-statement
}
^
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple: In instantiation of 'static constexpr bool std::_TC<<anonymous>, _Elements>::_ImplicitlyMoveConvertibleTuple() [with _UElements = {std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>}; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]':
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:626:362:   required by substitution of 'template<class ... _UElements, typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (5ul >= 1)), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(_UElements&& ...) [with _UElements = {std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>}; typename std::enable_if<(((std::_TC<(sizeof... (_UElements) == 1), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NotSameTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>()) && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (5ul >= 1)), bool>::type <anonymous> = <missing>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/functional:1363:8:   required from 'struct std::_Bind_simple<void (*(int, camera*, int*, int*))(int, camera*, int*, int*)>'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/thread:136:55:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(int, camera*, int*, int*); _Args = {int&, camera*, int*&, int*&}]'
/...snip.../ofunctions.hpp:3221:97:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:489:65: error: mismatched argument pack lengths while expanding 'std::is_convertible<_UElements&&, _Elements>'
return __and_<is_convertible<_UElements&&, _Elements>...>::value;
^~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:490:1: error: body of constexpr function 'static constexpr bool std::_TC<<anonymous>, _Elements>::_ImplicitlyMoveConvertibleTuple() [with _UElements = {std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>}; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]' not a return-statement
}
^
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple: In instantiation of 'static constexpr bool std::_TC<<anonymous>, _Elements>::_NonNestedTuple() [with _SrcTuple = std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&&; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]':
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:686:422:   required by substitution of 'template<class ... _UElements, class _Dummy, typename std::enable_if<((std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && std::_TC<(std::is_same<_Dummy, void>::value && (1ul == 1)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NonNestedTuple<tuple<_Elements ...>&&>()), bool>::type <anonymous> > constexpr std::tuple< <template-parameter-1-1> >::tuple(std::tuple<_Args1 ...>&&) [with _UElements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}; _Dummy = void; typename std::enable_if<((std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_MoveConstructibleTuple<_UElements ...>() && std::_TC<(1ul == sizeof... (_UElements)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && std::_TC<(std::is_same<_Dummy, void>::value && (1ul == 1)), void (*)(int, camera*, int*, int*), int, camera*, int*, int*>::_NonNestedTuple<tuple<_Elements ...>&&>()), bool>::type <anonymous> = <missing>]'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/functional:1363:8:   required from 'struct std::_Bind_simple<void (*(int, camera*, int*, int*))(int, camera*, int*, int*)>'
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/thread:136:55:   required from 'std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (*)(int, camera*, int*, int*); _Args = {int&, camera*, int*&, int*&}]'
/...snip.../ofunctions.hpp:3221:97:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:495:244: error: wrong number of template arguments (6, should be 2)
return  __and_<__not_<is_same<tuple<_Elements...>,
                                                                                                                                                                              ^    
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/type_traits:1558:8: note: provided for 'template<class _From, class _To> struct std::is_convertible'
struct is_convertible
^~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/include/g++-v6/tuple:502:1: error: body of constexpr function 'static constexpr bool std::_TC<<anonymous>, _Elements>::_NonNestedTuple() [with _SrcTuple = std::tuple<void (*)(int, camera*, int*, int*), int, camera*, int*, int*>&&; bool <anonymous> = true; _Elements = {void (*)(int, camera*, int*, int*), int, camera*, int*, int*}]' not a return-statement
}
^
CMake Error at ocapture_generated_ocapture.cu.o.cmake:282 (message):
Error generating file
/...snip.../build/CMakeFiles/ocapture.dir//./ocapture_generated_ocapture.cu.o

make[2]: *** [CMakeFiles/ocapture.dir/build.make:510: CMakeFiles/ocapture.dir/ocapture_generated_ocapture.cu.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:67: CMakeFiles/ocapture.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

几天来,我一直遇到你同样的问题,当我读到你关于"线程"的结论时,我设法创建了一个测试项目,该项目在GCC 6.1.0中失败,但在5.3.0中有效。

需要注意的是,当在CUDA下编译时,它会失败,也就是说,Launcher是一个.cu文件。如果您将其编译为.cpp文件,那么通过在编译过程中设置-phread标志,问题就会消失。

因此,我现在使用5.3.0。我在这里附上失败的代码。用来让它失败的软件:

CMake 10,忍者,GCC 6.3.0,CUDA 9.0.176

启动器:

#include "ClassWithT/Functions.hpp"
#include <stdlib.h>
#include <iostream>
int main()
{
int* m = (int*)malloc(2 * sizeof(int));
float* n = (float*)malloc(2 * sizeof(float));
m[0] = 5;
m[1] = 6;
n[0] = 2.5f;
n[1] = 5.6f;
Functions<int>* f = new Functions<int>(m, 2, 0);
std::cout << f->ManagingFutures() << std::endl;
Functions<float>* g = new Functions<float>(n, 2, 0);
std::cout << g->ManagingFutures() << std::endl;
return 0;
}

Functions.ipp:

#pragma once
#include "Functions.hpp"
template<class T>
Functions<T>::Functions(T* list, int numValues, bool type)
{
valuesList = list;
numberOfValuesInList = numValues;
typeOfOperation = type;
}
template<class T>
T Functions<T>::DoSomeStuff()
{
T intAmount;
if (typeOfOperation == 0)
{
intAmount = valuesList[0] + valuesList[1];
}
else
{
intAmount = valuesList[0] - valuesList[1];
}
return intAmount;
}
template<class T>
T Functions<T>::ManagingFutures()
{
std::future<T> testThread;
testThread = std::async(std::launch::async, &Functions::DoSomeStuff, this);
return testThread.get();
}

Functions.hpp:

#pragma once
#ifndef FUNCTIONS_HPP
#define FUNCTIONS_HPP
#include <future>
template<class T>
class Functions
{
public:
Functions(T* intList, int numIntegers, bool type);
T DoSomeStuff();
T ManagingFutures();
private:
T* valuesList;
int numberOfValuesInList;
bool typeOfOperation;
};
#include "Functions.ipp"
#endif

我还不明白它为什么会失败。我可以向Nvidia或GCC发布错误吗?

如果你想复制它并遇到任何麻烦,请随时发表评论,我会帮你的!

致以最良好的问候!

最新更新