" 'this' may not be used in this context"
2017-11-24 15:38
267 查看
” ‘this’ may not be used in this context”
class A { private: int length; public: A(); void display(int l=this->length) { cout<<"the length is "<<l<<endl; } }; int main() { A a; a.display(); return 0; }
函数原型如下:
void display(int l=this->length)
实际编译器翻译后的如下:
void display(A * this, int l=this->length); //translated by the compiler
所以会出现问题,因为this被传入了两次,而c++不允许这样传入参数
在这个问题出现的同时还会报一个错误:invalid use of non-static data member
这是一个问题导致的两处报错。
解决方法:
因为我出现这个错误的原因是想省事直接传默认参数,所以我的解决方案也比较省事,我的方法是去掉后面传入的一个含有this的参数,在调用的时候加上相关文章推荐
- "Your computer could not be joined to the domain. You have exceeded the maximum number of computer accounts you are allowed to create in this domain. Contact your system administrator to have this limit reset or increased."
- The project was not built due to "Could not delete ...".Fix the problem, then try refreshing this project and building it since it may be inconsistent.
- Compilation Error:function 'NAME_IN' may not be used in SQL
- A class file was not written. The project may be inconsistent, if so try refreshing this project and building it
- jqGrid ---Grid can not be used in this ('quirks...
- Only one SparkContext may be running in this JVM
- jqGrid不支持IE8的解决办法(Grid can not be used in this ('quirks') mode)
- "无法解析的外部符号" 和 "This function or variable may be unsafe"
- 编译出错"new types may not be defined in a return"
- PLS-00231错误:function name may not be used in SQL
- 如何解决 "This function or variable may be unsafe" 的问题
- Ubuntu——"xxx is not in the sudoers file.This incident will be reported" 错误解决方法
- "==" and "!=" should not be used when "equals" is overridden
- Exception in thread "main" org.apache.axis2.AxisFault: Namespace URI may not be null
- Linux 'XXXXXX' "is not in the sudoers file. This incident will be reported" 解决方法
- CoovaChilli-1.3.0编译时出现main-opt.c:781: error: ‘ptr’ may be used uninitialized in this function的解决方法
- "The object cannot be deleted because it was not found in the ObjectStateManager."
- FAIL - Context /SsmApp is defined in server.xml and may not be undeployed
- warning: ‘p’ may be used uninitialized in this function
- gcc warning: warning: 'tick' may be used uninitialized in this function