0
using/typedef
エイリアスをクラス外に移動することなく、以下のような循環依存関係を壊す方法はありますか?クラス/構造体内で定義されたパブリックエイリアス(typdef/using)へのC++の循環依存性
// header A.h
#ifdef A
#define A
#include "B.h"
class A {
using ID = uint32_t;
void some_func(B::ID id);
};
#endif A
// header B.h
#ifdef B
#define B
#include "A.h"
class B {
using ID = uint64_t;
void some_func(A::ID id);
};
#endif B
// main.cpp
#include "A.h"
int main() {...}
ガード#ifdef
sが存在し、IDは、より複雑なタイプ(struct
等)とすることができると仮定する。
編集:明確化のビット:エイリアス名は必ずしも同じではありません(つまり、ID
ではありません)。
変形例:
// header A.h
#ifdef A
#define A
#include "B.h"
class A {
using SomeAliasInA = uint32_t;
void some_func(B::SomeAliasInB id);
};
#endif A
// header B.h
#ifdef B
#define B
#include "A.h"
class B {
using SomeAliasInB = std::string;
void some_func(A::SomeAliasInA id);
};
#endif B
感謝を。エイリアスが同じ名前の場合、あなたのソリューションは合理的です。質問を明確にして更新しました。 –
@JimmyBazooka同じ答えが適用されます。あなたは 'types'構造体で必要なだけ多くのtypedefまたは別名を持つことができます。 – Quest