gpt4 book ai didi

language-agnostic - 类型和类别有什么区别?

转载 作者:行者123 更新时间:2023-12-03 03:35:05 25 4
gpt4 key购买 nike

什么使类型不同于类,反之亦然?

(在与语言无关的一般意义上)

最佳答案

以下答案来自Gof书( Design Patterns )

An object's class defines how theobject is implemented. The classdefines object's internal state andthe implementation of itsoperations.

In contrast, an object'stype only refers to its interface - aset of requests to which it canrespond.

An object can have many types,and objects of different classes canhave the same type.

//example in c++
template<typename T>
const T & max(T const &a,T const &b)
{
return a>b?a:b; //> operator of the type is used for comparison
}

max 函数需要一个具有操作> 的类型,并以其自己的类型作为其接口(interface)之一,任何满足上述要求的类都可以用于生成特定的 max<特定类/原始类型> 函数那个类(class)。

关于language-agnostic - 类型和类别有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/468145/

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