Visibility of template specialization of C++ function

前端 未结 9 688
情书的邮戳
情书的邮戳 2021-01-01 11:21

Suppose I have fileA.h which declares a class classA with template function SomeFunc(). This function is implemented directly

9条回答
  •  迷失自我
    2021-01-01 11:53

    I had the same problem with gcc4, here is how i solved it. It was more simple a solution than what i was lead to believe by previous comments. The previous posts ideas were correct but their syntax didn't work for me.

    
        ----------header-----------------
        template < class A >
        void foobar(A& object)
        {
          std::cout << object;
        }
    
        template <> 
        void foobar(int);
    
        ---------source------------------
        #include "header.hpp"
    
        template <>
        void foobar(int x)
        {
          std::cout << "an int";
        }
    
    

提交回复
热议问题