make_pair(字符串、类):错误:标记之前的预期主表达式
make_pair(string, class): error: expected primary-expression before â)â token
错误:在标记之前需要主表达式
我不完全确定这里发生了什么,因为我的朋友们也在做这个项目,似乎无法判断出哪里出了问题。如有任何关于此错误的帮助,我们将不胜感激。错误所指的行上有一条注释指出了这一点。我正试图通过下面的代码将一对插入到地图中。
theCandidates
是map<string, class>
,在这种情况下,该类被称为Candidate。
void TallyVotes::initialize(Scanner& inStream)
{
numberOfLosers = 0;
numberOfVotes = boost::lexical_cast<int>(inStream.next());
numberOfCandidates = boost::lexical_cast<int>(inStream.next());
for(int i = 0; i < numberOfVotes ; i++)
{
for(int j = 0; j < numberOfCandidates ; i++)
{
theVotes[i][j] = inStream.next();
cand = theVotes[i][j];
if(i == 0)
{
theCandidates.insert(make_pair(cand, Candidate));//ERROR ON THIS LINE
}
}
}
} // void TallyVotes::initialize(Scanner& inStream)
make_pair
函数采用两个值作为参数,而不是一个值和一个类型。
尝试例如
make_pair(cand, Candidate())
// Note parentheses ^^
表达式Candidate()
创建一个临时对象,然后将其复制到std::map
中。
相关文章:
- 在 C++ 中使用正则表达式错误时出现问题 括号表达式中的范围无效
- C++ 标记之前预期主表达式'('错误
- 正则表达式中带有卷轴大括号的正则表达式错误
- C++初学者错误:主要表达式错误
- 代数树表达式C++错误:未解析的外部符号"Public:_thiscall AlgebraicTreeExpression::~AlgebraicTreeExpression(void) ..."
- 使用多线程处理对象数组 - 无效使用 void 表达式错误
- 为什么 if constexpr 不会使这个核心常量表达式错误消失?
- 提升正则表达式错误:未初始化的提升::match_results
- C++比较表达式错误
- C++ "主表达式"错误
- C++ 正则表达式错误(未处理的异常)
- 'this'不能用于常量表达式错误 (C++)
- 代码块引发有关for_each的预期主表达式错误
- Boost Regex中的命名子表达式错误
- C++之前的主要表达式错误
- Ubuntu 上的正则表达式错误
- C++正则表达式错误
- 理解常量表达式错误
- 成员函数和预期的主表达式错误
- Xcode中应有表达式错误