小编Саш*_*лов的帖子

不完整类型定义后的 Typedef

我需要siginfo_t在标头中声明不完整的类型(可能是),并在源导入中sys/signal.h定义该类型的一些系统标头()。

所以,问题来了:

// a.h
struct siginfo_t;
void foo(siginfo_t*);
Run Code Online (Sandbox Code Playgroud)
// a.cpp
#include "a.h"
#include <signal.h> 
void foo(siginfo_t* x) { /* implementation */ };
Run Code Online (Sandbox Code Playgroud)

但在 signal.h 中它的定义如下:

typedef struct siginfo_t { /* */ } siginfo_t;
Run Code Online (Sandbox Code Playgroud)

编译器错误:error: typedef redefinition with different types ('struct siginfo_t' vs 'siginfo_t').

如何实现没有错误呢?谢谢!

c++ struct typedef compiler-errors redeclaration

0
推荐指数
1
解决办法
145
查看次数

标签 统计

c++ ×1

compiler-errors ×1

redeclaration ×1

struct ×1

typedef ×1