C ++中的子类型与派生类型 [英] Subtypes vs Derived Types in C++

查看:162
本文介绍了C ++中的子类型与派生类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近听说我的一位同事声称子类型"的概念未在C ++中定义.他声称子类型"在C ++术语中正确地称为派生类型".这是真的?如果我有:

I recently heard one of my coworkers claim that the concept of a "subtype" is not defined in C++. He claims that "subtypes" are rightly called "derived types" in C++ terminology. Is this true? If I have:

class A { }; class B : public A { };

class A { }; class B : public A { };

我可以将B称为A的子类型吗?还是仅在C ++中将B称为A的派生类型"是有效的?

Can I call B a subtype of A? Or is it only valid to call B a "derived type" of A in C++?

推荐答案

子类型不是C ++中常见术语的一部分. Wikipedia中的定义(感谢Chad)非常广泛,而C ++中的定义可以表示多种不同的事物,包括但不限于继承.例如,来自给定类别和指针的所有迭代器类型都可以是迭代器概念的子类型,因为它们可以被替换为需要该概念的模板(包括标准库算法).

Subtype is not part of the common jargon in C++. The definition in Wikipedia (thanks Chad) is quite broad and in C++ could represent multiple different things, including but not limited to inheritance. For example, all iterator types from a given category and pointers could be subtypes of the iterator concept as they can be substituted in templates that require that concept (including the standard library algorithms).

通常,我会使用 derived ,对于相同的(不同语言),其他替代词可能包括扩展(类型A扩展为B)或 inherits .

I would use derived in general, other alternative words for the same (in different languages) could include extends (type A extends B) or inherits.

这篇关于C ++中的子类型与派生类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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