Skip to content

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

@fattyturkey

Description

@fattyturkey

一个常量引用可以引用一个不同类型的对象,通过生成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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions