B
Ben Thomas
Hello,
I have the following code which I don't understand why it works :
#include <iostream>
using namespace std;
void DontWork (unsigned int& i) {
cout << i << endl;
}
void Work (unsigned int const& i) {
cout << i << endl;
}
void main () {
signed int i = 1;
// DontWork (i);
Work (i);
}
What I don't understand is why the compiler can find an implicit
conversion when I add the const modifier, but it is unable to do so
without it.
(I know I should not code like this, but I just want to understand the
behavior.)
Thank you,
Ben.
I have the following code which I don't understand why it works :
#include <iostream>
using namespace std;
void DontWork (unsigned int& i) {
cout << i << endl;
}
void Work (unsigned int const& i) {
cout << i << endl;
}
void main () {
signed int i = 1;
// DontWork (i);
Work (i);
}
What I don't understand is why the compiler can find an implicit
conversion when I add the const modifier, but it is unable to do so
without it.
(I know I should not code like this, but I just want to understand the
behavior.)
Thank you,
Ben.