标签:
(一)invalid initialization of non-const reference of type ‘float&’ from a temporary of type ‘float’
代码如下:
#include <iostream>
using namespace std;
void update(float& i) {
cout << i << endl;
}
void g(double d, float r) {
update(2.0f);
update(r);
update(d);
}
int main(void) {
g(3.2, 1.3);
}原因在于调用update(2.0f)和update(d)出错了:
对于普通的T&的初始式必须是一个类型T的左值;
对非const引用参数不允许做类型转换,非const引用不能引用一个常量。
这个问题有待进一步讨论。
(二)error: ‘cout’ was not declared in this scope
这真是个弱智问题,在文件头部加上
#include <iostream> using namespace std;
标签:
原文地址:http://www.cnblogs.com/tuhooo/p/5436131.html