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

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

What is wrong in this code?

#include 

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

template

        
4条回答
  •  独厮守ぢ
    2020-11-22 10:04

    Even you have:

    TMap::Type = std::map. 
    

    But before you call test(tmap)

    TMap::Type tmap;
    tmap[1.1] = 5.2;
    double d = test(tmap); 
    

    You already have it declared as

    TMap::Type tmap;
    

    why this information can not be utilized. #typedef is not just simple string replacement.

提交回复
热议问题