Archived

This forum has been archived. Please start a new discussion on GitHub.

Custom implementation of Slice class destructor in C++

Hello, I am using Ice 3.5.1 for C++. I have written a class in Slice. When I run slice2cpp, a C++ class is generated for the Slice class, but it has an empty virtual protected destructor. But my real need is to implement a custom destructor, to run code specific to my application. Therefore, my question is: How can I tell Slice (or in any other way) not ot generate the implementation of the class destructor? Thank you in advance. Best regards, Juan Angel

Comments

  • benoit
    benoit Rennes, France
    Hi Juan,

    It's not possible to modify the generated code to implement your virtual destructor for the generated class. However, it's possible to extend the generated class and implement a custom destructor in the derived class. You can configure Ice to instantiate your specialization rather than the default generated class using object factories.

    See https://doc.zeroc.com/pages/viewpage.action?pageId=14031061#C++MappingforClasses-ClassOperationsinC++ for an example on how to register an object factory in C++.

    Cheers,
    Benoit.
  • Thank you Benoit.

    But now I have another question: My Slice class only has data members, it does not have any operation. Can I create an object factory even if the class has no operations?

    Thank you,
    Juan

  • benoit
    benoit Rennes, France
    Hi,

    Yes, this also works for Slice classes without operations.

    Cheers,
    ​Benoit.