I always make a class called Constants in Java to store constant values which will be used in an application.
For all the classes of the application
class Constants {
public static final int GOOD_RES = 1;
public static final int BAD_RES = 0;
public static final int FILE_NOT_READ = 10;
// To be continued
}
or for a single class
class SomeClass {
private static final int GOOD_RES = 1;
private static final int BAD_RES = 0;
private static final int FILE_NOT_READ = 10;
// To be continued
}
How to do the same in C++? I can make a class in a header file with declarations and place definitions in a CPP file. For example.
Header file.
class const_values {
const static int GOOD_STATE = 1;
const static int BAD_STATE = 2;
const static string s;
}
CPP file
string const_values::s = "lorem ipsum";
Is it OK?
Use namespace for that:
constants.h:
main.cpp:
Output: 1 test