IDL interface, C++, CORBA, I'm dealing with “conflicting return type specified for” and “invalid abstract return type for member function ‘virtual…”

StackOverflow https://stackoverflow.com/questions/11763036

Question

For over 3 days I've been dealing with CORBA and C++ and my app interface written in IDL.

My app interface looks like this:

#ifndef __FORUM_INTERFACE_IDL__
#define __FORUM_INTERFACE_IDL__

#include "Forum.idl"
typedef sequence<Forum> Forums;

interface ForumInterface
{
    Forums getForumList(in Forum f);
    Forums getUsersForumList(in long UsersID);
    void addNewTopic(in Forum f, in long UsersID, in string title);
};

#endif

I "compile" it to *.hh and *.cc files by : omniidl -bcxx ForumInterface.idl

My Forum-object (also defined in IDL) looks like:

#ifndef __FORUM_IDL__
#define __FORUM_IDL__

interface Forum
{
    long getForumID();
    void setForumID(in long id);
    string getForumName();
    void setFroumName(in string name);
    Forum getForumParent();
    void setForumParent(in Forum f);
};

#endif

I "compile" it to *.hh and *.cc files by : omniidl -bcxx Forum.idl

I tried to write an implementation of both Forum and ForumInterface. I started with Forum, here's definition of class FroumImpl:

#ifndef __FORUMIMPL_H__
#define __FORUMIMPL_H__

#include "Forum.hh"

class ForumImpl : public POA_Forum
{
    private :

        long id;
        char *name;
        ForumImpl parent;

    public :

        long getForumID();
        void setForumID(long id);
        char* getForumName();
        void setFroumName(const char* name);
        ForumImpl getForumParent();
        void setForumParent(ForumImpl f);
};

#endif

and it's declaration (for now it's empty):

#include "ForumImpl.h"

long ForumImpl::getForumID(){}
void ForumImpl::setForumID(long id){}
char* ForumImpl::getForumName(){}
void ForumImpl::setFroumName(const char* name){}
ForumImpl ForumImpl::getForumParent(){}
void ForumImpl::setForumParent(ForumImpl f){}

I tried to compile it,

g++ -c ForumImpl.cpp -I$OMNIORB_HOME/include -I$OMNIORB_HOME/include/omniORB4

but got errors:

In file included from ForumImpl.cpp:1:0: ForumImpl.h:12:19: error: field ‘parent’ has incomplete type ForumImpl.h:20:19: error: conflicting return type specified for ‘virtual ForumImpl ForumImpl::getForumParent()’ Forum.hh:161:21: error: overriding ‘virtual _objref_Forum* _impl_Forum::getForumParent()’ ForumImpl.h:20:19: error: invalid abstract return type for member function ‘virtual ForumImpl ForumImpl::getForumParent()’ ForumImpl.h:6:7: note: because the following virtual functions are pure within ‘ForumImpl’: Forum.hh:162:16: note: virtual void _impl_Forum::setForumParent(Forum_ptr) ForumImpl.h:21:14: error: cannot declare parameter ‘f’ to be of abstract type ‘ForumImpl’ ForumImpl.h:6:7: note: since type ‘ForumImpl’ has pure virtual functions ForumImpl.cpp: In member function ‘virtual ForumImpl ForumImpl::getForumParent()’: ForumImpl.cpp:7:11: error: invalid abstract return type for member function ‘virtual ForumImpl ForumImpl::getForumParent()’ ForumImpl.h:6:7: note: since type ‘ForumImpl’ has pure virtual functions ForumImpl.cpp: At global scope: ForumImpl.cpp:8:42: error: cannot declare parameter ‘f’ to be of abstract type ‘ForumImpl’ ForumImpl.h:6:7: note: since type ‘ForumImpl’ has pure virtual functions

the worst thing is I have no idea why this code gives me such errors ... I mean, I defined all of ForumImpl functions ... so any of them is virtual now. I spent hours and hours trying figure out what's wrong with this but have no clue :(

Could anyone help? My files: http://www6.zippyshare.com/v/69552292/file.html I added to this tar archive a Makefile, so simply run command "make all" and this will do everything.

I would be very grateful if anyone could tell my why I got those error and what to do to fix this, I really need it. Cheers:)

EDIT:

I changed my ForumImpl.h and ForumImpl.cpp:

#ifndef __FORUMIMPL_H__
#define __FORUMIMPL_H__

#include "Forum.hh"

class ForumImpl : public POA_Forum
{
    private :

        long id;
        char *name;
        ForumImpl *parent;

    public :

        long getForumID();
        void setForumID(long id);
        char* getForumName();
        void setFroumName(const char* name);
        ForumImpl* getForumParent();
        void setForumParent(ForumImpl *f);
};

#endif

#include "ForumImpl.h"
long ForumImpl::getForumID(){}
void ForumImpl::setForumID(long id){}
char* ForumImpl::getForumName(){}
void ForumImpl::setFroumName(const char* name){}
ForumImpl* ForumImpl::getForumParent(){}
void ForumImpl::setForumParent(ForumImpl *f){}

but this gave me those erros:

g++ -c ForumImpl.cpp -IMNIORB_HOME/include -IMNIORB_HOME/include/omniORB4 In file included from ForumImpl.cpp:1:0: ForumImpl.h:20:20: error: invalid covariant return type for ‘virtual ForumImpl* ForumImpl::getForumParent()’ Forum.hh:161:21: error: overriding ‘virtual _objref_Forum* _impl_Forum::getForumParent()’

Was it helpful?

Solution

The signature for ForumImpl::getForumParent() should look like this:

Forum_ptr getForumParent();

For more information you should download the IDL to C++ mapping document from the OMG website. Also check out Henning & Vinowski's book Advanced CORBA Programming with C++.

OTHER TIPS

The method signatures in ForumImpl should match the base class as generated in Forum.hh. They should return just Forum. I don't know omniorb in detail, but TAO has hundreds of examples that use this, for example our bank example, you can also find that online at https://svn.dre.vanderbilt.edu/viewvc/Middleware/trunk/TAO/examples/Simple/bank/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top