c++ - 头文件中的异常数据类型和 #include

标签 c++ header ftp

因此,我正在为 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/

相关文章:

c++ - 使用继承拆分模板代码是正确的方法吗?

php - 尝试从仅支持主动模式的 EC2 访问 FTP

visual-studio-2010 - Visual Studio FTP发布不会关闭连接?

c++ - 在 C++ 中动态创建对象?

c++ - 从一个或多个线程访问 std::list

c++ - Qt拖放: Add support for dragging files to the application's main window

java - commons-net FTPSClient 的替代品?

c++ - 处理霍夫曼压缩/解压缩中的最后一个字节

php - 如何使用 PHP 对 CSV 文件进行排序而不对标题行进行排序?

头文件中的 C++ 'using' 和 'using typename'