Trouble with dependent types in templates

后端 未结 2 1171
庸人自扰
庸人自扰 2020-12-30 01:35

I\'m having trouble with templates and dependent types:

namespace Utils
{
    void PrintLine(const string& line, int tabLevel = 0);
    string getTabs(in         


        
2条回答
  •  渐次进展
    2020-12-30 02:37

    Well, the warning says:

    dependent name is not a type. prefix with 'typename' to indicate a type

    The dependent name (that is, the iterator in std::set::iterator) is not a type. You need to prefix it with typename to indicate a type:

    typename std::set::iterator
    

    So, your declaration should be:

    template
    set findAll_if(typename set::iterator begin, typename set::iterator end, Predicate pred)
                                                    note added typename ^
    

    (and the definition should match the declaration)

提交回复
热议问题