gpt4 book ai didi

python - Python C API 中的多重继承

转载 作者:行者123 更新时间:2023-11-28 17:22:52 25 4
gpt4 key购买 nike

如何使用从多个其他类型继承的 Python C API 创建类型?

Python 文档包含一个类型继承自另一种类型的示例,但我找不到任何示例或提及多重继承。

最佳答案

C API 不支持多重继承。您必须自己调用 PyType_Type,模拟标准的 Python class 语句。这记录在 specifying a base type for an extension type 的 C API 部分下。 :

PyTypeObject* PyTypeObject.tp_base

An optional pointer to a base type from which type properties are inherited. At this level, only single inheritance is supported; multiple inheritance require dynamically creating a type object by calling the metatype.

This field is not inherited by subtypes (obviously), but it defaults to &PyBaseObject_Type (which to Python programmers is known as the type object).

关于python - Python C API 中的多重继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40593529/

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