Archived

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

SLICE - Problems referencing classes in reopened modules.

Hi everyone, I hope the title gets the point across.

I just started using ICE and i'm impressed by what i've seen sofar. I do have one question in regards to managing SLICE in a best practice sort of way.

I've got a number of slice files that define DTO classes for specific domains, but i'm having trouble referencing these dto's within the same module, from different files. i.e. dto class Test is in the same module as the interface PersistenceTest, but defined in different files. Compilation of the slice will tell me that class Test isn't defined.

I can make my slice compile if i include the slice files that contain the referenced classes, using the c++ preprocessor include commands, but is this reallly necessary?

Thanks in advance!

Comments

  • benoit
    benoit Rennes, France
    Hi and welcome to the forums!

    Yes, if you don't include the Slice file that contains the referenced class, the Slice compiler will complain that you didn't declare that class. Another option would be to use a forward declaration for the referenced class instead of including the Slice file containing its definition. See the following sections in the Ice manual for more information:

    http://www.zeroc.com/doc/Ice-3.3.1/manual/Slice.5.4.html
    http://www.zeroc.com/doc/Ice-3.3.1/manual/Slice.5.12.html

    Cheers,
    Benoit.
  • benoit wrote: »
    Hi and welcome to the forums!

    Yes, if you don't include the Slice file that contains the referenced class, the Slice compiler will complain that you didn't declare that class. Another option would be to use a forward declaration for the referenced class instead of including the Slice file containing its definition. See the following sections in the Ice manual for more information:

    http://www.zeroc.com/doc/Ice-3.3.1/manual/Slice.5.4.html
    http://www.zeroc.com/doc/Ice-3.3.1/manual/Slice.5.12.html

    Cheers,
    Benoit.

    Thank you for clearing that up! I appreciate it. This leads me to another SLICE question.

    Is it possible to avoid having a slice file cluttered with namespace references? (i.e. DTO::User::BasicUser). I couldn't find like any preprocessor command like "using".

    Thank you in advance!
  • benoit
    benoit Rennes, France
    You don't need to specify the module for types defined at the same scope or enclosing scopes but you need to specify the module if the type is defined in another scope, there's no "using" keyword like in C++ to allow changing the lookup rules. See here in the Ice manual for more information on names/scopes and lookup rules.

    Cheers,
    Benoit.
  • Thanks for your assistance, Benoit. I've gotten the information i needed about constructing slice.

    Cheers! :)