vendredi 1 juillet 2016

Why using 0 as default non type template parameter for void* is not allowed

Why does the following code fail to compile? Even though it is legal to do void* ptr = 0;

template <void* ptr = 0>
void func();

int main() {
    func();
    return 0;
}

I ask because I found that a very trusted source did something similar and it failed to compile on my machine

NOTE Should have posted the compiler error along with my question so here it is

so_test.cpp:1:23: error: null non-type template argument must be cast to template parameter type 'void *'
template <void* ptr = 0>
                      ^
                      static_cast<void *>( )
so_test.cpp:1:17: note: template parameter is declared here
template <void* ptr = 0>
                ^
so_test.cpp:5:5: error: no matching function for call to 'func'
    func();
    ^~~~
so_test.cpp:2:6: note: candidate template ignored: substitution failure [with ptr = nullptr]: null non-type template argument must be cast to template parameter type 'void *'
void func();
     ^

Aucun commentaire:

Enregistrer un commentaire