C ++中的Java / C#切片 [英] C++ slicing in Java / C#

查看:97
本文介绍了C ++中的Java / C#切片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CAN C ++切片适用于其他语言也一样,如Java / C#?

Can C++ slicing apply to other languages too, like Java/C#?

推荐答案

切片也就是说,如果您分配一个子类实例一个超类的变量,由子类包含的额外信息是切片关,因为超变量没有多余的空间来存储子类的此额外信息。

Slicing means that if you assign a subclass instance to a superclass variable, the extra information contained by subclass is "sliced" off, because the superclass variable doesn't have the extra space to store this extra information of the subclass.

这不会在Java中也没有与C#发生,因为所有的对象变量引用;当你指定一个子类的实例,以一个超类变量,你实际上只是复制参考;子类对象本身保持不变。

This doesn't happen in Java nor with C#, because all object variables are references; when you assign a subclass instance to a superclass variable, you actually just copy the reference; the subclass object itself remains intact.

这篇关于C ++中的Java / C#切片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆