【发布时间】:2023-03-23 09:06:01
【问题描述】:
假设我有一个 std::vector::iterator 类型的变量 x 被分配(出于其他原因)新位置,例如
new((void*)&x) std::vector<int>::iterator();
如何以符合标准的方式调用其析构函数?正在做
x.std::vector<int>::iterator::~iterator();
例如在 gcc 中有效,但在 clang 中无效。
【问题讨论】:
-
认为 x 是 C 结构的成员,例如
struct A { std::vector<int>::iterator x; ... }给你一个struct A*来初始化和销毁。 (在我的例子中,它是一个 Python 扩展类实例。)
标签: c++ templates destructor nested-class