我在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"
#include "THandle.h" struct A; class B { THandle<A> SomeAInstance; };