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

any way to extend slice2cpp?


Just wonder if there is any way to extend slice2cpp so that I can have additional methods added for data-only SLICE classes?

The method to be added may be very simple. The reason for not adding this methods to SLICE class definitions is due to the overhead caused by introducing operations to SLICE classes: 1) the class can not be instantiated directly since they r abstract 2) object factories need to be defined to help ICE communicator.

So I wonder if the SLICE2CPP can be extensible?

Thanks a lot.


  • No, there are no extension hooks for the kind of thing you want to do. I am not sure that we'd add such hooks either--we have not exactly been overwhelmed with requests for this.

    Note that, as far as run-time overhead is concerned, there is no difference between instantiating a concrete class as generated by the Slice compiler, and instantiating a concrete class that you write yourself. One way to get your additional methods into a Slice class would be:
    // Slice
    class X {
        int i;

    This generates a corresponding C++ class X, from which you can derive your own class with the additional methods:
    // C++
    class MyX : public X {
        void foo();

    Whenever the Ice run time receives an X over the wire, it calls the object factory for X, so all you need to do is register an object factory for X that instantiates a MyX instead.