Pass a Qpair value in function
-
May i know how will i pass a QPair value in a function?
-
Suppose i have
QPair <int, int >pair;
pair.first = 4;
pair.second = 3;Now how will i call myFunction () ?
How to pass pair to my Function?
Will the following work/
myFunction(pair); -
Yes, why wouldn't it ?
If you have doubts write some code to test it.
-
May i know how to initialize QPair with qmakePair.
QPair <int, int >pair = qMakePair(4, 3);
Will the above work? -
Look at qpair.h:
@QPair<T1, T2> qMakePair(const T1 &x, const T2 &y)
{
return QPair<T1, T2>(x, y);
}@This means that "qMakePair(4, 3)" is nothing but a shorthand for something like "QPair<int, int > myPair(4, 3)", which in turn does the same as:
@QPair <int, int > myPair;
myPair.first = 3;
myPair.second = 4;@So I see no reason why it should not work. But why not try yourself?
(there often is more than one to achieve the same thing)