gpt4 book ai didi

c++ - 为什么我们不能使用两个具有不同类型但完全相同的成员的结构(或类)互换?

转载 作者:行者123 更新时间:2023-12-01 15:10:20 28 4
gpt4 key购买 nike

假设我有两个名为StudentEmployee的结构(或类),并且StudentEmployee具有完全相同的成员。
我的问题是,为什么我不能执行以下操作:

Student s;
Employee e;

Student* p;
p = &s;
p = &e; // this will cause a compilation error

最佳答案

因为C++是nominally typed,所以不是structurally typed

关于c++ - 为什么我们不能使用两个具有不同类型但完全相同的成员的结构(或类)互换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63039161/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com