// Error.h
#pragma once
struct Test;
class Error {
public:
void Callfunction (Test& ref);
};
// Test.h
typedef struct _Test {
int a;
} Test; // Error C2371
/* 혹은 이름을 생략하고 선언한 경우
typedef struct {
int a;
} Test;
*/
위와 같이 Error.h에서 구조체 Test를 전방선언하고 Test.h에서 Test를 정의하는 경우 C2371오류가 발생한다.
해결방법
1. 태그명과 타입명을 동일하게 정의
// Test.h
typedef struct Test {
int a;
} Test;
2. typedef를 사용하지 않고 구조체 정의
// Test.h
struct Test {
int a;
};
728x90
'Language > C' 카테고리의 다른 글
[C/C++] #if ... #elif ... #endif 할때 정의 조건문 넣는방법 (0) | 2024.04.27 |
---|---|
[C] printf 서식문자 (0) | 2022.09.16 |
[C, C++] 가변인자를 가지는 매크로 구현하기 (0) | 2022.08.19 |
[Complie Process] 컴파일의 4단계 과정 (0) | 2022.02.03 |
[C] ANSI Escape sequences (0) | 2021.10.04 |
댓글