这种问题一般是因为引用了匿名变量。涉及左值和右值的区别。一般函数的参数如果是一个表达式,那将会产生一个第3方的匿名变量传入这个函数中,此时如果引用,没用什么实际意义。 c++中临时变量不能作为非const的引用参数 ...
先看代码 不想看代码可以直接看代码后的问题描述 header.h ifndef HEADER H define HEADER H define defaultSize include lt iostream gt include lt string.h gt using namespace std class myString private: char ch int curLength int ...
2019-09-10 17:01 0 4075 推荐指数:
这种问题一般是因为引用了匿名变量。涉及左值和右值的区别。一般函数的参数如果是一个表达式,那将会产生一个第3方的匿名变量传入这个函数中,此时如果引用,没用什么实际意义。 c++中临时变量不能作为非const的引用参数 ...
1. 问题代码 2. 编译错误 3. 原因分析 non-const lvalue reference cannot bind to a temporary 根据编译错误提示可以知道,不能将形参begin、end绑定到a.begin()和a.end()的返回值 ...
1.问题 类的构造函数定义为: 如果这样初始化对象: 就会报错误: cannot bind non-const lvalue reference of type 'std::__cxx11::string& 而如果构造函数中的string添加 ...
如下这段代码,编译报错: Error : initial value of reference to non-const must be an lvalue #include <iostream> using namespace std; void test(float ...
char & operator[](int i); const char & operator[](int i);/*const char & operator(int i);*/ 编译出错: error C2556: 'const char & ...
1.代码 2.make 结果 3.分析与解决 就拿(a + b)来说,a+b的值会存在一个临时变量中,当把这个临时变量传给f时,由于testint的声明中,参数是int&,不是常量引用,因为c++编译器的一个关于语义的限制。如果一个参数是以非const引用 ...
解决方法:在参数前面加一个cosnt或者把引用符号去掉 ...
被问及以下问题: #include<iostream> using namespace std; void func( int * & ...