0

我最近从 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
4

1 回答 1

1

几天来我遇到了完全相同的问题,当我阅读您关于“线程”的结论时,我设法创建了一个在 GCC 6.1.0 中失败但在 5.3.0 上运行的测试项目。

需要注意的是,在 CUDA 下编译时会失败,即 Launcher 是一个 .cu 文件。如果将其编译为 .cpp 文件,则可以通过在编译过程中设置 -pthread 标志来解决问题。

因此,我现在正在使用 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;
}

函数.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();
}

函数.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 发出错误吗?

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

最好的问候,伙计们!

于 2017-12-02T13:23:21.877 回答