convert static final from java to c++

  • Thread starter silverburgh.meryl
  • Start date
S

silverburgh.meryl

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.
 
J

Jay_Nabonne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,153
Latest member
NamKaufman
Top