+ 3

What are ideal situation when we use pair<> in c++. Can we compare two different objects using pair<obj1,obj2> p ; like this ..

22nd Mar 2018, 11:11 AM
Usman Ali
Usman Ali - avatar
5 Answers
+ 7
This class couples together a pair of values, which may be of different types (T1 and T2). The individual values can be accessed through its public members first and second. T1 Type of member first, aliased as first_type. T2 Type of member second, aliased as second_type. LIKE THAT: #include <iostream> using namespace std; int main () { pair<int, int> k = make_pair(1,2); }
22nd Mar 2018, 11:22 AM
Baraa AB
Baraa AB - avatar
+ 5
I was trying to compare two objects of class, is it possible ?
22nd Mar 2018, 11:24 AM
Usman Ali
Usman Ali - avatar
+ 5
it is better i think to use: bool operator==(const name1& l1, const name2& l2);
22nd Mar 2018, 11:35 AM
Baraa AB
Baraa AB - avatar
+ 5
Good idea ! thanks man
22nd Mar 2018, 11:37 AM
Usman Ali
Usman Ali - avatar
0
you are welcome
7th May 2018, 7:00 PM
Wasim Abbasi
Wasim Abbasi - avatar