Archived

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

Question about self-referential class definition

Hi all,

I'm quite new to ICE and am now working on a server-side Java process which will expose an ICE interface for client app invocation. What I'm doing now is to define an .ice file and use slice2java for code generation. Everything looks pretty good until I want to define a class ABC which needs to contain a member variable with ABC array datatype (or List<ABC>).

I tried both:

Approach 1
=========================
sequence<ABC> MyList;

class ABC {
MyList attr1;
};
=========================

and

Approach 2
=========================
class ABC {
MyList attr1;
};

sequence<ABC> MyList;
=========================

and slice2java complained both.

May I ask the proper way to accomplish what I'm trying to do?

Thanks a lot!

Marco

Comments

  • dwayne
    dwayne St. John's, Newfoundland
    You should forward declare the ABC class before using it in the sequence definition.
    // Forward declare class ABC
    class ABC;
    
    sequence<ABC> MyList;
    
    // Define class ABC
    class ABC
    {
        MyList attr1;
    };
    
  • Oh, it just works, brilliant!!