Why aren't template specializations allowed to be in different namespaces?

前端 未结 3 1046
南方客
南方客 2020-12-08 12:16

Please, see what I am trying to do:

#include 
namespace first
{
 template 
 class myclass
 { 
  T t;
 public:
  void who_are_y         


        
3条回答
  •  無奈伤痛
    2020-12-08 12:29

    Why would such a question even arise? Without understanding that it is difficult to even begin answering it.

    Specialization modifies the main template. It is not "detachable" in any way from the main template. In certain way, as a high-level concept, it is still the same template (even though at lower level it is defined as an independent one). So, for obvious reasons, it is in the same namespace as the main template.

    Sorry, I just can't provide a better explanation, since I don't understand how such a question can arise.

    BTW, what do you mean by "in different namespace"? You want the specialization to be a member of different namespace? Or you want your specialization to be defined in a different namespace in the source code, but still remain a member of the original namespace?

提交回复
热议问题