Table of Contents Previous Next
Logo
Client-Side Slice-to-C++ Mapping : 6.8 Mapping for Constants
Copyright © 2003-2010 ZeroC, Inc.

6.8 Mapping for Constants

Slice constant definitions map to corresponding C++ constant definitions. Here are the constant definitions we saw in Section 4.9.5 on page 103 once more:
const bool      AppendByDefault = true;
const byte      LowerNibble = 0x0f;
const string    Advice = "Don't Panic!";
const short     TheAnswer = 42;
const double    PI = 3.1416;

enum Fruit { Apple, Pear, Orange };
const Fruit     FavoriteFruit = Pear;
Here are the generated definitions for these constants:
const bool          AppendByDefault = true;
const Ice::Byte     LowerNibble =     15;
const std::string   Advice =          "Don't Panic!";
const Ice::Short    TheAnswer =       42;
const Ice::Double   PI =              3.1416;

enum Fruit { Apple, Pear, Orange };
const Fruit         FavoriteFruit =   Pear;
All constants are initialized directly in the header file, so they are compile-time constants and can be used in contexts where a compile-time constant expression is required, such as to dimension an array or as the case label of a switch state­ment.

Table of Contents Previous Next
Logo