Consider this code:
#include <vector>
#include <iostream>
class num{
int a;
int b;
public:
num(int a_, int b_): a(a_), b(b_){}
int Geta(){return a;}
int Getb(){return b;}
};
int main(){
num a(2, 5);
num b(32, 654);
std::vector<num> nums;
nums.push_back(a);
nums.push_back(b);
std::vector<num>::iterator iter = nums.begin();
std::cout << iter->Geta()<< " " <<(*iter).Getb() << std::endl;
return 0;
}
This works, but I don't know which way is better to access the element of the array with the iteratoriter->
or (*iter)
.
I think that this example is a particular case where both works. Can you give me a code where is possible to see the difference (and why)?