J
John Ratliff
Let's say I had a program which uses some constants. Would it be
"better" to declare them like this:
#ifndef __MY_HDR_FILE
#define __MY_HDR_FILE
#define STRING_CONST "some string..."
#define INT_CONSTANT 4852
#endif
Or like this:
-- hdr.h --
#ifndef __MY_HDR_FILE
#define __MY_HDR_FILE
namespace myns {
static const char [] STRING_CONST;
static const int INT_CONSTANT;
}
#endif
-- const.c --
using namespace myns;
const char [] STRING_CONST = "some string...";
const int INT_CONSTANT = 4852;
----------------------------------------------------
I know there is some general animosity against the preprocessor. But
aside from that, is it better C++ to use the second method?
--Dominic
"better" to declare them like this:
#ifndef __MY_HDR_FILE
#define __MY_HDR_FILE
#define STRING_CONST "some string..."
#define INT_CONSTANT 4852
#endif
Or like this:
-- hdr.h --
#ifndef __MY_HDR_FILE
#define __MY_HDR_FILE
namespace myns {
static const char [] STRING_CONST;
static const int INT_CONSTANT;
}
#endif
-- const.c --
using namespace myns;
const char [] STRING_CONST = "some string...";
const int INT_CONSTANT = 4852;
----------------------------------------------------
I know there is some general animosity against the preprocessor. But
aside from that, is it better C++ to use the second method?
--Dominic