Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么指向常量的指针不能指向一个不同类型的对象 #90

Open
fattyturkey opened this issue Mar 8, 2020 · 1 comment

Comments

@fattyturkey
Copy link

一个常量引用可以引用一个不同类型的对象,通过生成temp对象完成:
double a=2.1;
const int &b=a;
这个是可以的:
double a=2.1;
const int temp=a;
const int &b=temp;
b其实绑定在temp上,那为什么指针不可以呢?
double a=2.1;
const int *b=&a;
不可以这样吗?
double a=2.1;
const int temp=a;
const int *b=&temp;

@rexzhong79626
Copy link

指针是一个对象,既然是对象就要类型强一致。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants