修复循环依赖性c ++ 17标头

问题描述 投票:0回答:2

我正在使用Clang C ++ 17编译器,并且收到警告:

declaration of 'struct Xchart' will not be visible outside of this function. 

此警告指向使用不同头文件中声明的结构的函数声明。我相信这是由两个头文件中的循环依赖关系引起的,但我仍无法解决警告

Header toolkit.h声明函数MyFunction,该函数使用结构Xchart作为输入。这是警告的地方。

toolkit.h

#ifndef _TOOLKIT_H
#define _TOOLKIT_H 1

#define _WINDOWS 1
#include <windows.h>

short WINAPI MyFunction(struct Xchart *mychart ); <--Warning Here

#pragma pack(push, 1)
#pragma pack(pop)
#endif /*_TOOLTKIT_H */

Header mystruct.h声明Xchart结构

mystruct.h

#ifndef _mystructs_h
#define _mystructs_h 1

#include "toolkit.h"

#pragma pack(push, 1)

struct Xchart { 
  int MyDays;   
  short LoadMe;   
  wchar_t MyLabel[100]; 
};

#pragma pack(pop)
#endif /* _mystructs_h */

您能否显示如何更改这两个头文件以解决警告?

c++ clang forward-declaration
2个回答
0
投票

通常的解决方法很简单:


-1
投票

struct以下关键字在这里有问题:

© www.soinside.com 2019 - 2024. All rights reserved.