Home Help Center

Custom implementation of Slice class destructor in C++

jafontjafont Member Juan Angel Font BanegasOrganization: University of Castilla la ManchaProject: Practices for subject in Master in Computer Science
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

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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.
  • jafontjafont Member Juan Angel Font BanegasOrganization: University of Castilla la ManchaProject: Practices for subject in Master in Computer Science
    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

  • benoitbenoit Rennes, FranceAdministrators, ZeroC Staff Benoit FoucherOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi,

    Yes, this also works for Slice classes without operations.

    Cheers,
    ​Benoit.
Sign In or Register to comment.