Why can't the template argument be deduced when it is used as template parameter to another template?

前端 未结 4 2022
无人共我
无人共我 2020-11-22 09:02

What is wrong in this code?

#include 

template
struct TMap
{
    typedef std::map Type;
};

template

        
4条回答
  •  余生分开走
    2020-11-22 09:53

    I don't think "we can't do this" argument is correct. If we slightly modify this example, the compiler is happily deducing arguments for us.

    template
    struct TMap //...
    
    template 
    struct tmap_t : TMap::Type {};
    
    template
    T test(tmap_t tmap) // ...
    
    tmap_t tmap;  // ...
    double d = test(tmap);  // compiles just fine.
    

    I don't see a huge difference between the original example and mine. The real issue here seems that C++ treats typedefs and type declarations differently

    Is this a good thing?

提交回复
热议问题