Why can’t I pass string.begin() right away for the function with (string::Iterator& it) argument?

  arguments, c++, iterator, reference

I tried to pass str.begin() iterator for calling a function with (string::Iterator& it) argument.

When I tried func(str.begin()), it didn’t work.
On the other hand, when I tried pre-declaration for the iterator, it worked pretty well.

It goes like

string::iterator it = str.begin();
func(it);

In my opinion, I see no difference between those ways. Can anybody tell me why the first one didn’t work?

Source: Windows Questions C++

LEAVE A COMMENT