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

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

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.

 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 20:06
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.