TITLE: Non-const reference arguments and temporary generation PROBLEM: jliberty@zdi.ziff.com (Jesse Liberty) Is it legal to pass an int to a function which expects an unsigned int & ? RESPONSE: clamage@Eng.Sun.COM (Steve Clamage), 12 Aug 94 No. When you pass an object to a non-const reference, the types must be compatible. The reason is that the function might modify the actual parameter (since the reference is to a non-const). If the actual parameter is not the same type as the reference expects, the compiler must create a temporary object of the correct type initialized with the value of the actual argument and pass a reference to the temp. If the function then attempts to modify the actual argument, it modifies the temp instead; the temp disappears when the function exits and the actual argument is unchanged. This would be quite a surprise to the programmer who called the function. What if the compiler didn't create a temp, but just passed a reference to the actual argument, whatever it happened to be? Then the function would have the wrong idea about the actual argument, possibly overwriting areas outside the actual argument or storing data in the wrong format (long vs float, for example, which might be the same size). If the formal parameter of the function is a reference to a const, then the compiler can safely create a temp and pass a reference to it. The function promises not to modify the actual argument, so a copy is as good as the original. Once again, though, the value of the actual argument must be converted to the type expected by the function -- hence the temp. In your particular case, 'int' and 'unsigned int' are not compatible. Either may be implicitly converted to the other, which is why you get no complaint when passing one to a const reference to the other.