Skip to main content

Why is there a problem in a class implementing 2 idl classes that have a common base class?

  • February 16, 2013
  • 0 replies
  • 0 views

Problem:

  • Product Name : VisiBroker C
  • Product Version: 5.x and above
  • Product Component: IDL
  • Platform : NA
  • Compiler : NA

Why does the following program not compile in C ?

The virtual functions in question are _type_info, _safe_narrow and _safe_downcast_ops.

class A {
  public:
    virtual void m() {
      cout <<" from A " <<endl;
    }
};

class B : public virtual A {
  public:
    virtual void m() {
      cout <<"from B " <<endl;
    }
};

class C : public virtual A {
  public:
    virtual void m() {
      cout <<"from C " <<endl;
    }
};

class D : public virtual C, public virtual B {
};

int main()
{
  cout <<"Hi there" <<endl;
  return 0;
}

Resolution:

This is not a VisiBroker bug.

The virtual functions in question are _type_info, _safe_narrow and _safe_downcast_ops. These functions need to be generated as virtual in all the generated classes to make the generated code work correctly.

If an implementation class needs to implement both the interfaces in the scenario mentioned, it has to implement the above 3 methods.

This is a design problem. If you want to design the IDL in that way, you cannot implement two interfaces using a single C class. To use a single C class for implementation, we need to complete the diamond shape in IDL. In other words, define another IDL like:

module derv3 {
  interface foobar : derv1::foo, derv2::bar{
  };
};

And use POA_derv3::foobar to derive the implementation class.

 


#VisiBroker
#COMPILER
#IDL
#c
#C
#Security