0
using/typedef
별칭을 클래스 외부로 이동하지 않고 다음과 같은 순환 종속성을 끊는 방법이 있습니까? 클래스/구조체 내에서 정의 된 public 별칭 (typdef/using)에 대한 순환 종속성
// 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는 (a
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