C++ template specialization for pointer?

前端 未结 3 1863
青春惊慌失措
青春惊慌失措 2020-12-19 04:43

I read book < C++ Templates - the Complete Guide > and learned template specialization for pointer. (maybe I misunderstand this part of the book)

(1) Here\'s my s

3条回答
  •  鱼传尺愫
    2020-12-19 05:30

    as you've been already told, partial specialization of function templates are not allowed. You can use std::enable_if for this:

    template ::value>* = 0>
    void func(T val) { std::cout << val << std::endl; }
    
    template ::value>* = 0>
    void func(T val) { func(*val); }
    

    If you are looking for simpler syntax, wait for concepts

提交回复
热议问题