根据 C++ 标准 n3376,以下代码格式错误。
using cell = pair<void*, cell*>; // ill-formed
有没有办法实现cell
,这是一个合理的数据结构,而无需在C++中定义新的cell
类?
最佳答案
以(相当多的)可读性为代价,您可以使用自定义对
和一些专门化来实现类似的东西
struct self {};
template<typename F, typename S>
struct pair
{
F first;
S second;
// ...
};
template<typename F>
struct pair<F, self*> : pair<F, pair*>
{
};
然后你写
using cell = pair<void*, self*>;
关于c++ - 如何定义与 `using cell = pair<void*, cell*>` 等效的单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49504005/