Default template parameter partial specialization

前端 未结 3 722
心在旅途
心在旅途 2020-12-04 16:19

Please explain to me why the following piece of code complies and works perfectly. I am very confused.

#include
template

        
3条回答
  •  误落风尘
    2020-12-04 17:02

    When you write Base<> base; the compiler will try to find out if instantiation of Base<> class is possible or not if it is possible the code would work fine. In this case it is possible due to the default template argument of Base because the compiler knows if you if you write Base<> it needs to create a object of Base. i.e: because of:

    template
    class Base
    {};
    

    So the code works fine.

提交回复
热议问题