By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,795 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,795 IT Pros & Developers. It's quick & easy.

convert static final from java to c++

P: n/a
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.

Feb 7 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Tue, 07 Feb 2006 09:16:36 -0800, si***************@gmail.com wrote:
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?


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

Feb 7 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.