Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GET SET VALUES TO USE IN MY CODE

Status
Not open for further replies.

ankoump

Programmer
May 29, 2002
11
0
0
DE
I HAVE VARIOUS VALUES IN MY CODE THAT I HAVE TO KEEP ENTERING SUCH AS DIMENSIONS IS IS POSSIBLE TO SET THESE VALUES SAY IN ANOTHER FILE AND THEN JUST GET MY PROGRAM TO USE THESE VALUES ALL THE TIME
 
Yes, there's a couple of ways to do this:

The simplest way is to use #define statements in your class header file. Any code which has access to the header file will also have access to your constants:

#define kConstant1 233
#define kConstant2 128

class SomeClass
{
...
};

Note there are no semi-colons after the constant definitions.

You can use the constants in your code like such:

int x = 10;
int y = x + kConstant1;

You can name the constants whatever you want. There are a couple of conventions for this including the one you see above whereby all constants begin with a lower-case 'k'.

There are other ways to add constants to your code. You may also want to read up on 'enum' structures.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top