this的用法 - 写c++时,用this指针指向字符串时报错
大家讲道理
大家讲道理 2017-04-17 11:48:43
0
1
331
#include class father { public: char* name[16]; int money; father(char* name,int money); }; father::father(char*name,int money) { this->name=name; this->money=money; }

在vs2012中编写,倒数第二行指向name的的this下有红色浪线提示说“表达式必须是可修改的左值”,请问为什么不能这么写

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复 (1)
洪涛

char* name[16] 是指针数组,而 father::father(char* name, int money) 的参数 name 是一个指针,当然不能直接赋值了。

可以写成 this -> name [0] = name;

不过我猜题主的原本意思肯定不是这个。

    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责声明 Sitemap
    PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!