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

前端 未结 3 1048
南方客
南方客 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:41

    It complicates things:

    namespace first
    {
      template  class TArray;
    }
    
    namespace second
    {
      using first::TArray;
    
      template  class TArray < Node >;
      //                              ^
      // Only there do you realize it's a specialization and not another template
    }
    

    I understand your frustration, I often wished for the same thing. It seems definitely possible and I certainly don't buy the logical grouping argument, however I must admit that it would require even more effort from the compiler writers, and parsing C++ correctly is already difficult enough as it stands.

    Templates are a bit messy in C++ if you want my opinion, but then it's easy to say with the benefit of experience and after having seen 20 years of use :)

提交回复
热议问题