How to resolve the error: called object type 'char' is not a function or function pointer

How to resolve the error: called object type 'char' is not a function or function pointer

所以,在一个程序中,我试图从堆栈中打印一对。代码如下:

#include <iostream>
#include <stack>
#include <utility>
using namespace std;

int main()
{
    stack<pair<char, int>> deleteOperations;
    stack<pair<pair<char, char>, int>> replaceOperations;
    deleteOperations.push(make_pair('a', 1));
    replaceOperations.push(make_pair(make_pair('b', 'c'), 2));
    cout << deleteOperations.top().first();
    cout << replaceOperations.top().first().first();

    return 0;
}

错误是:

test.cpp:12:41: error: called object type 'char' is not a function or function pointer
    cout << deleteOperations.top().first();
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
test.cpp:13:13: error: type 'std::__1::pair<char, char>' does not provide a call operator
    cout << replaceOperations.top().first().first();
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

std::pair<>::first是成员变量,不是函数,用deleteOperations.top().first;replaceOperations.top().first.first

就可以了