首页 > 写c++时,用this指针指向字符串时报错

写c++时,用this指针指向字符串时报错

    #include<iostream>
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下有红色浪线提示说“表达式必须是可修改的左值”,请问为什么不能这么写


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

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

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

【热门文章】
【热门文章】