c++ - C++ 结构的前向声明

标签 c++ visual-c++ struct forward-declaration

下面是我的头文件

#ifndef _ASYNCHRONOUSCLASS_H
#define _ASYNCHRONOUSCLASS_H
#include "stdafx.h"
#include <windows.h>

typedef int (*functionCall)(void *);
typedef void * voidPtr;

class  AsynchronousFunction{    
//int returnVal; 
//functionCall fCall;
//voidPtr param;
//HANDLE m_hEvent;

struct pImpl;
pImpl* m_pImpl;

public:
    AsynchronousFunction(functionCall fCall, voidPtr param);
    ~AsynchronousFunction();
    void functionExecuter();
    int result();

protected:
private:    
};
#endif

在 cpp 文件中,我想实现包含以下详细信息的结构。

*//int returnVal;* 
*//functionCall fCall;*
*//voidPtr param;*
*//HANDLE m_hEvent;*

我该如何实现?什么是合适的,前向声明或指针实现?

最佳答案

在单个翻译单元中,您需要提供类型的定义。它看起来像:

struct AsynchronousFunction::Impl {
   // members and functions...
};

注意我把pImpl重命名为Implp中的p是指针,包含类中的成员是Impl* pImpl;.

关于c++ - C++ 结构的前向声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21978618/

相关文章:

c - 使用 qsort 对结构指针数组进行排序

c++ - 使用g++编译c和c++文件

c++ - 如何在没有控制台窗口的情况下从 C++ 启动 .jar 文件

c++ - 如何使用 boost::log::BOOST_TRIVIAL_LOG 更改默认格式?

c++ - 谁能帮我把这个结构翻译成delphi记录?

c++ - 如何将字符串添加到我的结构数组中,该数组在 C++ 中同时包含字符串和整数?

c++ - 在应用程序运行时禁用 WER

c# - 如何在 .NET 应用程序中使用 C++ 项目?

visual-studio - 如何在 Visual Studio 2010 中进行并行构建?

c++ - mingw和msvc之间的这种差异是否正常