代码之家  ›  专栏  ›  技术社区  ›  Jagannath

继承PortableServer::RefCountServantBase时出现编译错误

  •  0
  • Jagannath  · 技术社区  · 14 年前


    我得到下面的编译错误。

    “simples.cpp”,第108行:错误:无法为抽象类Simple\u i创建变量。

    “simples.cpp”,第108行:错误:PortableServer::ServantBase::_主接口(const PortableServer::ObjectId&,PortableServer::POA*)未被重写。
    检测到3个错误。

    如果我不继承RefCountServantBase,我不会得到任何编译错误。在samples.cpp中(这里没有显示),我们正在创建sample_i的实例并返回它。

    以下是示例代码:

    //样品i.h

    #include "simple_s.h"
    extern char* generate_unique_id();           // Generate unique uuids
    
    class Simple_i : public virtual POA_Simple
                     , virtual public PortableServer::RefCountServantBase
    {
      public:
        virtual char* to_lower(const char* val);
        virtual void  to_upper(char*&      val);
        virtual char* to_print(const char* val);
    };
    
    class SimpleFactory_i : public virtual POA_SimpleFactory
                            // , virtual public PortableServer::RefCountServantBase
    {
      public:
        virtual Simple_ptr find_simple();
    
        // To make simpapp scalable have the SimpleFactory use the user
        // supplied identifier in the Simple object reference it creates.
    };
    

    ================================================================================ //样品\u.h

    #include <string.h>
    #include "orbminor.h"
    #include <Tobj_ServantBase.h>
    
    #include "simple_c.h"
    
    class POA_Simple : public Tobj_ServantBase 
    {
        public:
    
            virtual ::CORBA::Char * to_lower (
                const char * str) = 0; 
    
            virtual void to_upper (
                ::CORBA::Char *& str) = 0; 
    
            virtual ::CORBA::Char * to_print (
                const char * str) = 0; 
    
            ::Simple_ptr _this();
    
            void invoke (::CORBA::ServerRequest_ptr _nasreq);
    
            ::CORBA::RepositoryId _primary_interface (
            const PortableServer::ObjectId &,
                PortableServer::POA_ptr);
    
        protected:
            virtual ~POA_Simple(){ }
    
        private:
            OBBArgument *getparams (::CORBA::Short, OBB::ServerRequest * SrvReq, ::CORBA::ULong & ArgCnt);
    
    };
    class POA_SimpleFactory : public Tobj_ServantBase 
    {
        public:
    
            virtual ::Simple_ptr find_simple () = 0; 
    
            ::SimpleFactory_ptr _this();
    
            void invoke (::CORBA::ServerRequest_ptr _nasreq);
    
            ::CORBA::RepositoryId _primary_interface (
            const PortableServer::ObjectId &,
                PortableServer::POA_ptr);
    
        protected:
            virtual ~POA_SimpleFactory(){ }
    
        private:
            OBBArgument *getparams (::CORBA::Short, OBB::ServerRequest * SrvReq, ::CORBA::ULong & ArgCnt);
    
    };
    #endif
    

    更新:
    现在,我有如下代码。这样好吗?我需要关心内存管理吗 在这里?还是我遗漏了什么?

    Tobj_Servant Server::create_servant(const char* intf_repos_id)
    {
        Tobj_Servant servant = NULL;
        if (!strcmp(intf_repos_id, _tc_SimpleFactory->id())) {
    
            servant = new SimpleFactory_i();
        }
        if (!strcmp(intf_repos_id, _tc_Simple->id())) {
            servant = new Simple_i();
        }
    
        servant->_add_ref();
        return servant; // unknown interface
    }
    
    2 回复  |  直到 14 年前
        1
  •  0
  •   Brian Neal    14 年前

    在较新版本的CORBA中,不推荐使用RefCountServantBase。您不再需要从它继承,因为自动生成的C++仆人现在提供相同的功能。您应该验证您正在使用的ORB是否实现了此更改。

    关于你的问题 create_servant() 功能。从仆人创造的角度来说应该是好的。然而,它看起来很奇怪,你可以分配多个东西给你的 servant

    我也不能说 _tc_SimpleFactory->id() _tc_Simple->id() 因为我不熟悉这些功能。如果它们返回CORBA字符串,那么就是在泄漏内存。

        2
  •  0
  •   rturrado    14 年前

    PortableServer::RefCountServantBase是抽象类吗?你能把申报单寄出去吗?

    其他两个编译错误引用的是PortableServer::ServantBase中的方法,这些方法没有在Simple\ i中实现。我猜它们是抽象的方法。我还注意到其中一个叫做invoke,POA\u Simple声明了一个invoke方法。也就是说,Simple\u i是由两个不同的基类继承一个名为invoke的方法。我不确定这是否会导致进一步的问题。