如何声明固定尺寸的模板,以便可以在类的正文中声明实例,而无需包含类型的.h文件?

问题描述 投票:0回答:1

我在thandle.h中定义以下模板作为句柄或所谓的任何内容(总是2个字节):

template<typename T>
struct THandle
{
    int16_t Index = -1;
    Thandle() = default;
    THandle(int16_t index) : Index(index) {}
    __forceinline T* operator->() const { return &T::Instances[Index]; }
    __forceinline explicit operator bool() const { return Index != -1; }
}

要存储在b.h中定义的任意B类中

class B { THandle<A> SomeAInstance; }
我怎么能做到这一点,以便我不必在b.h中包括a.h和thandle.h。

i前锋在thandle中宣布A和Thandle。


我怎么能做到这一点,以便我不必在b.h中包括a.h和thandle.h。

不需要

#include "A.h"
c++ compiler-optimization handle
1个回答
0
投票
#include "THandle.h" struct A; class B { THandle<A> SomeAInstance; };

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.