C ++ - 尝试使用模板时出错

时间:2016-05-04 09:16:23

标签: templates c++11

我是c ++的新手,并且很想使用模板。 我有一个可以获得某些类型的函数。

头:

template <typname T>
response_t send_sequence_to_device(map<const string_t, T*> msg2device_p,
    vector<response_t>& result_list, ushort num_attempts=SEND_NUM_ATTEMPTS);

来源:

template <typname T>
response_t send_sequence_to_device( map<const string_t, T*> msg2device_p,
    vector<response_t>& result_list, ushort num_attempts )
{
    bool is_ok_flag = true;
    response_t r;
    raftor1_logs_t* rlogs;
    map<const string_t, T*>::iterator msg_it;
    for( msg_it=msg2device_p.begin(); msg_it!=msg2device_p.end() and is_ok_flag; msg_it++ )
    {
        r = msg_it->second->send(msg_it->first, true, num_attempts);
        result_list.push_back(r);
        is_ok_flag = is_ok_flag and is_ok(r);

        if( not(is_ok_flag) )
        {
            stringstream ss;
            ss << "ALERT: Sequence aborted due to error on message [" << msg_it->first << "] ";
            if( r.erred() )
                ss << "due to communication failure.";
            else
                ss << "with error message [" << r.msg << "].";
            rlogs->alert.begin_record();
            rlogs->alert.write( ss.str() );
            rlogs->alert.end_record();
        }
    }

    if( is_ok_flag )
        r.set_ok("ok.\n");

    return r;
}

我收到以下错误:

  

device_manager.cpp | 1076 |错误:在'std :: map,T *&gt; :: iterator'之前需要'typename'因为'std :: map,T *&gt;'是一个依赖范围

1 个答案:

答案 0 :(得分:0)

下面:

map<const string_t, T*>::iterator msg_it;

你需要这个:

typename map<const string_t, T*>::iterator msg_it;