Search code examples
c++c++11templatesmetaprogramminggeneric-programming

redefinition of default argument for class<template-parameter-1-2>


I'm having some issue with the compiler on this SFINAE. Looks like it doesn't resolve the template before raising this error. Here is the code:

template<typename Sig, typename = typename std::enable_if<!std::is_pointer<Sig>::value>::type>
class   GLFunction { /* class def... */ };

template<typename FP, typename = typename std::enable_if<std::is_pointer<FP>::value>::type>
class   GLFunction { /* class def... */ };

Do you know how I can achieve this?

Thx.


Solution

  • Read the error, it tells you what's wrong: you can't redefine a default argument, you must only provide it once.

    What are you trying to do? Why have you defined the same template twice? Is one of them meant to be a partial specialization?

    Why can't you just do it the simple way, like this?

    // Primary template, with default argument:
    template <typename Sig, bool = std::is_pointer<Sig>::value>
    class   GLFunction { /* class def... */ };
    
    // Partial specialization used for pointers:
    template <typename FP>
    class   GLFunction<FP, true> { /* class def... */ };