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
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.