C++ / Cuda - template

Hello !

I don’t know if I’m in the right forum for this topic, if not I’m sorry !

Here is a little sample, a main.cu and a template “foo”. foo contains a thread that displays “YOLO !” with another thread for 2 seconds.


#include <chrono>
#include <thread>
#include <cuda_runtime.h>
#include "foo.cuh"

int main(int argc, char **argv)
    foo<uchar4> f(make_uchar4(1, 2, 3, 4));
    return 0;


#ifndef __FOO_H__
#define __FOO_H__

#include <thread>

template<typename T>
class foo

    foo(T value);

    void start();

    void run();

    void stop();

    T _value;
    std::thread _thread;
    bool _run;

#endif //__FOO_H__


#include "foo.cuh"

#include <iostream>
#include <cuda_runtime.h>

template<typename T>
foo<T>::foo(T value)
    _run = false;
    _value = value;

template<typename T>
void foo<T>::start()
    _run = true;
    _thread = std::thread(&foo<T>::run, this);

template<typename T>
void foo<T>::run()
    while (_run)
        std::cout << "YOLO ! " << _value.x << std::endl;

template<typename T>
void foo<T>::stop()
    _run = false;
    if (_thread.joinable()) _thread.join();

template class foo<uchar1>;
template class foo<uchar2>;
template class foo<uchar4>;
template class foo<char1>;
template class foo<char2>;
template class foo<char4>;
template class foo<short1>;
template class foo<short2>;
template class foo<short4>;
template class foo<ushort1>;
template class foo<ushort2>;
template class foo<ushort4>;
template class foo<float1>;
template class foo<float2>;
template class foo<float4>;

I have separated the definition and the declaration of the template “foo”. It’s allowed to do this only if the decleration all possible instance of “foo” are made.

Nothing special up to here. But the problem starts now !
I tried to build this example using VS 2015 and Cuda 8.0 but it does not work and I have the folling error (for each type):
error C2292: ‘foo’: best case inheritance representation: ‘virtual_inheritance’ declared but ‘single_inheritance’ required

I tried a lot of things but nothing seems to work. So I tried to build it on a Debian using g++5.4 and Cuda 8.0 and it works perfectly !! I also tried to build with VS 2015 only, without any reference to cuda and same result, it works !!

I have no idea why it does not build well, so if you have any idea you’re welcome !!