473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.

Feb 7 '06 #1
1 8580
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Petra Neumann | last post by:
Hello, I just came across some sample code where a variable has been defined as: static public final int TABLE = 1, LIST = 2; I was wondering if there is a difference to writing public static...
11
by: Altramagnus | last post by:
I have a complicated Region object, which I need to draw the outline, but not fill How can I convert the Region object to GraphicsPath object? or How can I draw the outline of the Region object?
3
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what...
4
by: mjahabarsadiq | last post by:
HELLO FRIENDS I HAVE ONE JAVA CODE WHICH PARSES AN XML FILE AND PRODUCE A QUERY TO CREATE TABEL IN A DATABASE. BUT I NEED THE CODE TO BE USED IN A JSP PAGE. HOW TO USE THIS PAGE WITH JSP. ...
2
by: minouparhizkar | last post by:
hi could anyone helping me to finish this i have no idea how to implement the program in java im trying to grabbing the pixel from image and then convert it to the txt file .i did that but it didnt...
6
by: nanaveraa | last post by:
Hai, i am tried to convert a .doc file into .rtf format file using jacob jar.i am written a code but its gives some error. In below i given that programs and error.please give me the solution...
11
by: Andreas Wollschlaeger | last post by:
Hi folks, as the subject says, i'm a poor Java programmer trying to transfer some of his wisdom into C++ world... here is what im trying to do this evening: Java has a nifty feature called a...
4
by: puneetsardana88 | last post by:
class abc1 { public void abc2(abc my) { this=my; } } class abc3 { public static void main(String args)
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.