获取错误:在"("令牌之前缺少模板参数
Getting the error:missing template arguments before '(' token
作为家庭作业,我们需要构建一个通用映射,该映射将适用于给定的不可修改的代码:
class startsWith {
char val;
public:
startsWith(char v) : val(v) {};
bool operator()(const std::string& str) {
return str.length() && char(str[0]) == val;
}
};
void addThree(int& n) {
n += 3;
}
int main() {
Map<std::string, int> msi;
msi.insert("Alice", 5);
msi.insert("Bob", 8);
msi.insert("Charlie", 0);
// add To every name with B 3 points, using MapIf
startsWith startWithB('B');
MapIf(msi, startWithB, addThree);
}
我写道:
template<typename T, typename S, typename Criteria, typename Action>
class MapIf {
public:
void operator() (Map<T,S>& map, Criteria criteria, Action act) {
for (typename Map<T, S>::iterator iter = map.begin(); iter != map.end(); ++iter) {
if (criteria(((*iter).retKey()))) {
act(((*iter).retData()));
}
}
}
};
我收到错误
Description Resource Path Location Type
missing template arguments before '(' token main.cpp /ex4 line 46 C/C++ Problem
在给定的代码中(以MapIf(msi, startWithB, addThree);
为单位)
我该如何解决它?(我只能更改我的代码)
看起来MapIf
应该是一个函数,而不是一个类:
template<typename T, typename S, typename Criteria, typename Action>
void MapIf(Map<T, S>& map, Criteria criteria, Action act)
{
for (typename Map<T, S>::iterator iter = map.begin(); iter != map.end(); ++iter) {
if (criteria(iter->retKey())) {
act(iter->retData());
}
}
};
相关文章:
- 如何在C++中使用X509证书模在令牌中查找私钥
- holeMenuProgram.cpp:38:1 错误:'}'令牌之前的预期主表达式
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- Arduino 用于语句错误。令牌之前的预期')' ';'。如何解决这个问题?
- 错误:令牌 { '{' 之前应存在非限定 ID
- 允许哪些令牌作为 #include 的参数?
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 它在 { 令牌之前给了我预期的标识符
- (错误:令牌之前'<<'预期的主表达式)
- 为什么 ## aka 令牌粘贴运算符不适用于 C 和 C++ 中的注释?
- 错误:"->"令牌之前的预期初始值设定项
- LINUX 操作系统上的错误:令牌之前预期的构造函数、析构函数或类型转换'('?
- 获取错误:在"("令牌之前缺少模板参数
- 3 错误:错误:未在此范围内声明'Entry'。错误:模板参数 1 无效。错误:令牌之前声明中的类型无效'('
- C++ - 令牌之前的预期主表达式'('并且缺少"("标记之前的模板参数
- 可变参数模板上下文中"..."令牌的规则是什么?
- 获取字符串令牌/参数作为解析
- Boost::program_options:带有固定和可变令牌的参数
- C++ 错误:在带有参数的构造函数中'*'令牌之前预期的主表达式
- 令牌的含义是什么"... ..."?即参数包上的双省略号运算符