下面是我的头文件
#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
重命名为Impl
,p
中的p
是指针,包含类中的成员是Impl* pImpl;
.
关于c++ - C++ 结构的前向声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21978618/