0

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?

Jarod42
  • 203,559
  • 14
  • 181
  • 302
  • 3
    Do you understand why `void f(int&); f(42);` won't work, but `int i = 42; foo(i);` works? – Jarod42 Mar 10 '21 at 10:40
  • 1
    please include the compiler error message in the question. Maybe you don't see the difference but there is one and the message should already tell a lot – 463035818_is_not_an_ai Mar 10 '21 at 10:40
  • Hi, Jarod42. Maybe i has it's memory space for referencing but 42 doesn't? – ivancoff Mar 11 '21 at 08:06
  • Jarod42, is it like there's no point of using reference argument for the function if I don't pass a declared variable and retain the changes in the function outside? – ivancoff Mar 11 '21 at 08:13

0 Answers0