簡體   English   中英

在C ++中使用內部類時,不允許指向不完整類類型的指針

[英]Pointer to incomplete class type is not allowed when using internal class in c++

我有一個類掃描器,在該類掃描器中,設備消息被聲明為內部,如下所示。 這是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;
}

您在CDeviceMessage *other前面的CDeviceMessage *other位置缺少CScanner::前綴

bool CScanner::CDeviceMessage::MatchesOtherMessage(CDeviceMessage *other)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM