我有一个类扫描器,其中设备消息被声明为内部的,如下所示。这是scanner.h文件代码:
#pragma once
class CScanner
{
public:
CScanner(void);
class CDeviceMessage;
~CScanner(void);
};
设备消息类在其方法中出现问题,此指针有错误。它说指向不完整类类型的指针不允许 CDeviceMessage.h。
CDeviceMessage.h 文件代码在这里,我不包括完整的代码,而是函数定义和声明,所以你可能会理解它:
#pragma once
#include "Scanner.h"
class CScanner::CDeviceMessage
{
bool MatchesOtherMessage(CScanner::CDeviceMessage * other);
};
错误出现的 CDeviceMessage.cpp 函数是这样的:
bool CScanner::CDeviceMessage::MatchesOtherMessage(CDeviceMessage *other)
{
if (other != NULL)
{
if ((this->imgMessage != NULL) && (other->imgMessage != NULL))/// here it gives on this pointer error that pointer to incomplete class type is not allowed
{
int timeDiff = this->imgMessage->OnlineMilliseconds
- this->imgMessage->OnlineMilliseconds;
if ((timeDiff > -20) && (timeDiff < 40))
{
return true;
}
}
}
return false;
}