我是新來的C++,並且正在使用模板。 我有一個可以獲得某種類型的函數。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|error: need 'typename' before 'std::map, T*>::iterator' because 'std::map, T*>' is a dependent scope
假設從這個原型中可以看到足夠的類型定義,它看起來很好。請發佈產生此錯誤的完整代碼段。 – Quentin
@ Quentin-這是標題中的相關代碼。你需要源代碼嗎? – Sarit8
你有'模板'在源? –
vu1p3n0x