0

I get the following error during compilation with MSVC. The main idea is to specialize function bar per size of the type. How this can be resolved? I prefer solution with templates not switch(sizeof(T))

struct S
{

    template<typename T>
    void foo(T t)
    {
        bar<sizeof(T), T>();
    }

    template<int Size, typename T>
    void bar(T t)
    {

    }

    template<typename T>  // : error C2768: 'S::bar' : illegal use of explicit template arguments
    void bar<1, T>()
    {

    }

};

Fully specialized template works

 struct S
{

    template<typename T>
    void foo(T t)
    {
        bar<sizeof(T)>();
    }

    template<int Size>
    void bar()
    {

    }

    template<>  // Works !!!
    void bar<1>()
    {

    }

};
Boris
  • 1,311
  • 13
  • 39

0 Answers0