vendredi 2 août 2019

Problem with writing full specialization for identifying void type

I am trying to specialize is_void struct. Here is my code that I am trying to compile:

#include <iostream>
using namespace std;

template<typename T>
struct is_void
{
    static constexpr bool value = false;
};

template<>
struct is_void<void>
{
    static constexpr bool value = true;
};

int main()
{
    printf("%d\n", is_void<int>::value);
    printf("%d\n", is_void<void>::value);
}

But it fails with the compile error:

error: explicit specialization of non-template struct 'is_void'
error: redefinition of 'is_void' as different kind of symbol

Right now I do not see any problems with this code. Appreciate any help.

Aucun commentaire:

Enregistrer un commentaire