错误:无效使用了不完整的类型“class Theron::EndPoint”

error: invalid use of incomplete type ‘class Theron::EndPoint’

本文关键字:类型 class EndPoint Theron 无效 错误      更新时间:2023-10-16

我在项目中使用Theron作为演员库,当我使用"hello-world"项目测试Theron时,我遇到了以下错误。

#include <iostream>
#include "Theron/Framework.h"
#include "Theron/Actor.h"
#include "Theron/Receiver.h"
#include "Theron/EndPoint.h"
using namespace std;
class Actor : public Theron::Actor
{
public:
    explicit Actor(Theron::Framework &framework) : Theron::Actor(framework)
    {
        RegisterHandler(this, &Actor::Handler);
    }
private:
    void Handler(const int &message, const Theron::Address from)
    {
        Send(message, from);
    }
};
int main()
{
    Theron::Receiver receiver;
    Theron::Framework framework;
    Actor actor(framework);
    framework.Send(int(0), receiver.GetAddress(), actor.GetAddress());
    receiver.Wait();
    return 0;
}

g++ -Wall -fexceptions -g -ITheron/Include/ -ITheron/Include/External/
-c /home/eliteyang/dev/test/main.cpp -o obj/Debug/main.o In file included from /home/eliteyang/dev/test/main.cpp:2:0: Theron/Include/Theron/Framework.h: In member function ‘bool Theron::Framework::SendInternal(Theron::Detail::MailboxContext*, Theron::Detail::IMessage*, Theron::Address)’: Theron/Include/Theron/Framework.h:999:23: error: invalid use of incomplete type ‘class Theron::EndPoint’
         if (!mEndPoint->Lookup(name, address.mIndex))
                       ^ In file included from Theron/Include/Theron/Framework.h:14:0,
                 from /home/eliteyang/dev/test/main.cpp:2: Theron/Include/Theron/Address.h:23:7: error: forward declaration of ‘class Theron::EndPoint’  class EndPoint;
       ^ In file included from /home/eliteyang/dev/test/main.cpp:2:0: Theron/Include/Theron/Framework.h:1002:29: error: invalid use of incomplete type ‘class Theron::EndPoint’
             return mEndPoint->RequestSend(message, name);
                             ^ In file included from Theron/Include/Theron/Framework.h:14:0,
                 from /home/eliteyang/dev/test/main.cpp:2: Theron/Include/Theron/Address.h:23:7: error: forward declaration of ‘class Theron::EndPoint’  class EndPoint;
           ^

我的环境是Ubuntu 15.04,代码块13.12,gcc 4.9.1。

非常感谢。

include语句是错误的,或者顺序错误。显然,Theron/Framework.h包含一些代码,这些代码需要类EndPoint的完整定义,但没有显式地包含头EndPoint.h,而是只提供了一个前向声明。

要解决此问题,您可以尝试在包含Framework.h之前包含EndPoint.h,或者用Theron/Theron.h全包包装器替换所有Theron包含。