【问题标题】:make_pair(string, class): error: expected primary-expression before â)â tokenmake_pair(string, class): error: â)â 标记之前的预期主表达式
【发布时间】:2014-03-15 20:44:52
【问题描述】:

错误:â)â 标记之前的预期主表达式

我不完全确定这里发生了什么,因为我的朋友也在从事这个项目,似乎无法判断出了什么问题。对此错误的任何帮助将不胜感激。错误所指的行有注释指出它。我正在尝试通过下面的代码将一对插入到地图中。

theCandidatesmap<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)

【问题讨论】:

    标签: c++ dictionary


    【解决方案1】:

    make_pair 函数接受两个作为参数,而不是一个值和一个类型

    试试例如

    make_pair(cand, Candidate())
    //      Note parentheses ^^
    

    表达式Candidate()创建一个临时对象,然后将其复制到std::map中。

    【讨论】:

    • 或者,将整行替换为theCandidates[cand];
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    • 2017-05-21
    • 1970-01-01
    相关资源
    最近更新 更多