加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C语言中的const声明的区别

发布时间:2020-12-16 05:55:05 所属栏目:百科 来源:网络整理
导读:有什么区别? void func(const Class *myClass) 和 void func(Class *const myClass) 也可以看看: C++ const question How many and which are the uses of “const” in C++? 可能还有别的… 解决方法 不同之处在于 void func(const Class *myClass) 你指
有什么区别?
void func(const Class *myClass)

void func(Class *const myClass)

也可以看看:

> C++ const question
> How many and which are the uses of “const” in C++?

可能还有别的…

解决方法

不同之处在于
void func(const Class *myClass)

你指向一个你不能改变的类,因为它是const.
但是您可以修改myClass指针(让它指向另一个类;这对调用者没有任何副作用,因为它的指针被复制,它只会改变本地的指针复制)
相反

void func(Class *const myClass)

现在myClass指向一个可以修改参数的类.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读