Hi, I am trying to create a function that has a parameter that is a pair<int,int> but i cant figure out how to pass the values to it, i seem to be getting errors of "no suitable constructor exists to concert int to std::pair<int,int>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
The code i have is
pair declared
std::pair<int,int>val;
void addVal(val, int addedVal);
void Val::addedVal(val, int addedVal)
{
}
and then I am trying to call the addedVal function using
addedVal(incomeA, incomeB, valAddedA);
the above line is where I am getting the error, so I must not be passing these values correctly, I am wondering how i pass these.
It looks like you have a “Val” class, holding some pair of income objects with an unknown-to-us relationship? And you wish to ‘add’ some integer value to this pair in some way using a member function? And possibly a free function as well?
Val.h
class Val
{
public:
std::pair<int, int>val;
void addVal(val, int addedVal)
}
Val.cpp
void Val::addVal(val, int addedVal)
{
}
but i want to be able to take in 3 values from the user and pass them into addedVal, so I am calling
addVal(incomeA, incomeB, valAddedA);
and incomeA, B and valAddedA are the values taken in from the user, but i think its a problem because it is two individual ints rather than passing them in as a pair, but I am not sure since i have not done this before. I am not sure ifthis has explained it better
#include <utility>
class Val
{
public:
using Pair = std::pair<int, int>;
Pair val;
void addVal(Pair v, int addedVal);
};
void Val::addVal(Pair v, int addedVal)
{
val = v;
// what is addedVal for?
}
int main()
{
int incomeA{1}, incomeB{2}, valAddedA{3};
Val val;
val.addVal(std::make_pair(incomeA, incomeB), valAddedA);
}