So, in a program I was trying to print a pair from a stack. The code is as follows:
#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;
}
The error is:
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.
CodePudding user response:
std::pair<>::first
is a member variable, not a function, just use deleteOperations.top().first;
and replaceOperations.top().first.first