questions
Aug 3, 2012 at 2:19pm UTC
differences between:
1 2
const int ROWS = 17;
const int COLS = 17
and
1 2 3 4
enum {
ROWS = 17,
COLS = 17
};
I know not to use macros for C++, but confused as to which to use between these two, which one uses less memory?
const void const printStr const ( const char *str)
a const before function returns const?
const inbetween void and printStr the same?
const before arguments the same as having const inside?
a const pointer is a reference, and a reference is automatically const?
Aug 3, 2012 at 2:38pm UTC
const int ROWS = 17;
const int COLS = 17;
This is good: you have two named constants.
1 2 3 4
enum {
ROWS = 17,
COLS = 17
};
This was a kludge used in C to avoid #define. You should use enums when you actually need to create a new type with a small set of possible values, not when you need a constant.
const void const printStr const ( const char *str)
This won't compile, you can't use const on the same type twice and you can't put const between the function name and the parameter list.
a const pointer is a reference
No it isn't. But you can obtain a const reference from a const pointer by dereferencing.
and a reference is automatically const?
No, it is as you define it:
int &
is not const,
const int &
is.
Topic archived. No new replies allowed.