Home Help Center

Question about self-referential class definition

chanmarcchanmarc Member Marco ChanOrganization: BarcapProject: Risk Management system
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

  • dwaynedwayne St. John's, NewfoundlandMember Dwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications Engine
    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;
    };
    
  • chanmarcchanmarc Member Marco ChanOrganization: BarcapProject: Risk Management system
    Oh, it just works, brilliant!!
Sign In or Register to comment.