It is legal.
You never call a constructor yourself; you are actually just declaring an unnamed or "temporary" object of type Item . See how the syntax evolves when you make an object unnamed:
Item a(img,i);
Even if it seems that you are calling the constructor as a function, it is not.
Anyway, you can use a temporary value like "rvalue" (because it is one) in function arguments and the like, what are you doing here.
By the way, do not use the old iostream.h and vector.h . They preceded 1998. In the ISO C ++ standard, you should use iostream and vector respectively. Standard C ++ headers do not end with ".h" (inb4, ignoring the C headers inherited for backward compatibility).
Lightness races in orbit
source share