因此,我正在为 Visual Studio 2012 中的程序编写一个小型 FTP 接口(interface),但遇到了头文件问题。我的类声明位于 FTP.h 中,如下所示:
// FTP.h
// class declaration for FTPConnection class
#include <WinInet.h> // <--- Line in question
class FTPConnection{
public:
FTPConnection(char *serverP, INTERNET_PORT portP, char *usernameP, char *passwordP);
~FTPConnection(void);
bool openConnection(void);
bool closeConnection(void);
bool downloadFile(char *webPath, char *localPath);
bool uploadFile(char *webPath, char *localPath);
bool status(void);
private:
HINTERNET internet;
HINTERNET FTPserver;
bool connectionStatus;
char *server;
INTERNET_PORT port;
char *password;
};
如果我省略“#include”行,则会收到有关未定义数据类型的错误,并且无法编译。我不想在需要使用该类的每个文件中都包含 WinInet.h,因为这似乎会让事情变得比必要的更加复杂,有没有办法做到这一点?
谢谢。
最佳答案
WinInet.h 是 Windows Internet API 的 header 。这可能包括给您带来错误的数据类型。
如果 FTP.h 包含 WinInet.h,只需将 FTP.h 包含在另一个文件中就足够了(您不需要直接包含 WinInet.h)。
关于c++ - 头文件中的异常数据类型和 #include,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20779670/