Can somebody help me understand why testing()
prints the same value (13) for x
and y
?
<code>#include <vector>
#include <unordered_set>
void testing(int x, int y) {
std::cout << x << " " << y << std::endl;
}
int main() {
std::unordered_set<int> tmp = {0, 1, 2, 3, 4};
std::vector<int> tmp1 = {10, 11, 12, 13, 14};
auto itr = tmp.begin();
testing(tmp1[*itr], tmp1[*(++itr)]);
return 0;
}
</code>
<code>#include <vector>
#include <unordered_set>
void testing(int x, int y) {
std::cout << x << " " << y << std::endl;
}
int main() {
std::unordered_set<int> tmp = {0, 1, 2, 3, 4};
std::vector<int> tmp1 = {10, 11, 12, 13, 14};
auto itr = tmp.begin();
testing(tmp1[*itr], tmp1[*(++itr)]);
return 0;
}
</code>
#include <vector>
#include <unordered_set>
void testing(int x, int y) {
std::cout << x << " " << y << std::endl;
}
int main() {
std::unordered_set<int> tmp = {0, 1, 2, 3, 4};
std::vector<int> tmp1 = {10, 11, 12, 13, 14};
auto itr = tmp.begin();
testing(tmp1[*itr], tmp1[*(++itr)]);
return 0;
}
This works fine:
<code>testing(tmp1[*itr], tmp1[*std::next(itr)])
</code>
<code>testing(tmp1[*itr], tmp1[*std::next(itr)])
</code>
testing(tmp1[*itr], tmp1[*std::next(itr)])
I get 14 and 13. I don’t understand why the same argument is passed to testing()
in the first case.
1