gpt4 book ai didi

c++ - 如何断言特定类在其布局中没有任何 vtbl 指针?

转载 作者:可可西里 更新时间:2023-11-01 15:41:34 25 4
gpt4 key购买 nike

我有一个简单的 RAII 类来确保正确处理一些句柄。现在我想断言,没有人会意外地向它添加任何虚拟方法。在我看来,我需要断言该类没有 vtbl 指针。

我该怎么做?是否可以在编译时断言?

编辑

我将满足于桌面编译器。据我所知,没有不使用 vtbl 实现多态性的桌面 c++ 编译器。

最佳答案

如果你有 C++11 库,你可以使用 std::is_polymorphic<T> :

If T is a polymorphic class (that is, a class that declares or inherits at least one virtual function), provides the member constant value equal true. For any other type, value is false.

关于c++ - 如何断言特定类在其布局中没有任何 vtbl 指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8804147/

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