convert static final from java to c++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • silverburgh.meryl@gmail.com

    #1

    convert static final from java to c++

    I am trying to convert this code from java to c++:

    public final class Type {

    public static final int DEFAULT = 1;
    private static int index = 2;
    public static final int COLUMN1 = (int) Math.pow(2, index++);
    public static final int COLUMN2 = (int) Math.pow(2, index++);
    public static final int COLUMN3 = (int) Math.pow(2, index++);
    public static final int COLUMN4 = (int) Math.pow(2, index++);

    }

    c++

    static const int index = 2;


    static const int COLUMN1 = pow(2, index++);
    static const int COLUMN2 = pow(2, index++);
    static const int COLUMN3 = pow(2, index++);
    static const int COLUMN4 = pow(2, index++);


    Should I put that in .cpp file? or .h file?

    Thank you.

  • Jay_Nabonne

    #2
    Re: convert static final from java to c++

    On Tue, 07 Feb 2006 09:16:36 -0800, silverburgh.mer yl@gmail.com wrote:
    [color=blue]
    > I am trying to convert this code from java to c++:
    >
    > public final class Type {
    >
    > public static final int DEFAULT = 1;
    > private static int index = 2;
    > public static final int COLUMN1 = (int) Math.pow(2, index++);
    > public static final int COLUMN2 = (int) Math.pow(2, index++);
    > public static final int COLUMN3 = (int) Math.pow(2, index++);
    > public static final int COLUMN4 = (int) Math.pow(2, index++);
    >
    > }
    >
    > c++
    >
    > static const int index = 2;
    >
    >
    > static const int COLUMN1 = pow(2, index++);
    > static const int COLUMN2 = pow(2, index++);
    > static const int COLUMN3 = pow(2, index++);
    > static const int COLUMN4 = pow(2, index++);
    >
    >
    > Should I put that in .cpp file? or .h file?[/color]

    If you must preserve that "index" business (which looks strange to me),
    then:

    <in .h file>

    class Type
    {
    static const int COLUMN1;
    static const int COLUMN2;
    static const int COLUMN3;
    static const int COLUMN4;
    };

    <in .cpp file>

    static int index = 2; // can't be const, since it's incremented

    const int Type::COLUMN1 = pow(2, index++);
    const int Type::COLUMN2 = pow(2, index++);
    const int Type::COLUMN3 = pow(2, index++);
    const int Type::COLUMN4 = pow(2, index++);

    - Jay

    Comment

    Working...