[omniORB] Interface Inheritance

Duncan Grisby duncan at grisby.org
Fri Jan 9 11:50:56 GMT 2009


On Friday 9 January, =?iso-8859-1?Q?V=E1zquez_Landa=2C_David?= wrote:

> Hi, I have a quick question.
> 
> Say I have an IDL such as:
> 
> Interface BaseInterface 
> {
> 	void forty(int two);
> };
> 
> Interface ChildInterface : BaseInterface 
> {
> };
> 
> And then in the c++ implementation I want to have something like:
> 
> // --- some random class does:
> Void test (BaseInterface_var baseInterface)
> {
> 	cout << "yay";
> }

You should never ever use a _var type as a parameter type. If you do,
you will get into a great deal of memory management pain. You should
always use the _ptr type as the parameter type.

> // --- I want to call this function with the child interface.
> 
> // For the sake of the argument:
> ChildInterface_var childInterface = getChildInterface();
> 
> // This doesn't work
> test(childInterface);
> 
> So, what would be the way to make this work?  Should I use
> ChildInterface_ptr instead?

No, you should define the parameter to the test() function as
BaseInterface_ptr. Then the code you have here will work just fine.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan at grisby.org     --
   -- http://www.grisby.org --



More information about the omniORB-list mailing list