Why assign const reference to non-const variable can't be displayed.

in main function, r can be displayed by cout, and when as a parameter assigned to const double &x, it just can't be displayed. only when type matched works.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void ref(const double &x);

int main()
{
	double m = 5;
	const double &r = m;
	cout << r;
	ref(m);
	cin.get();
}

void ref(const double &x)
{
	cout << x*x <<"d";
}


output:
5


could anyone tell me why?
Last edited on
I don't understand.

The output when I run this is as expected:
525d
what is your implementation? I use VC++ 2013
Compiled with gcc 4.7.1.
thank you!
But do you know why VC++ 2013 can't do that? do I need to set something?..
Last edited on
i'm running VS2010 and also get
525d
and I finally find the problem, because ref is a class name or something in vc++ 2013, so i occationally use it. I changed the name then worked~
Topic archived. No new replies allowed.