First, forgive my low English skill, please.
If you want to improve the legibility of your code, you can use reserved word like "#define" or "const". And few programmers like more "const" than "#define".
example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <conio.h>
#include <iostream>
using namespace std;
//#define LEFT 75
//#define RIGHT 77
//#define UP 72
//#define DOWN 80
const int LEFT = 75;
const int RIGHT = 77;
const int UP = 72;
const int DOWN = 80;
int main()
{
int c;
while(1)
{
c = getch();
if(c == 224)
{
c = getch();
switch(c)
{
case LEFT:
cout << "left" << endl;
break;
case RIGHT:
cout << "right" << endl;
break;
case UP:
cout << "up" << endl;
break;
case DOWN:
cout << "down" << endl;
break;
}
}
}
return 0;
}
|
Or otherwise const used in this case.
1 2 3 4 5 6 7 8 9 10
|
class AAA
{
int a[100000];
int b[50000];
int c[300000];
};
void Function(AAA ob)
{
}
|
1) AAA is very big object.
2) And function parameter is operating by copy.
3) You only want to read a AAA's data.
3) But 1) and 2), create a very big another AAA data.
4) So you decide to change parameter type.
1 2 3
|
void Function(AAA& ob)
{
}
|
5) But this code is, If you change ob's data in Function, together changed the original AAA's data(not in Function's).
6) Maybe you think "Why so play the foolish action? I will never change ob.". But If your program is very big, you can forget that. Or otherwise If you work other programmers, they can't read your think.
So,
1 2 3
|
void Function(const AAA& ob)
{
}
|
7) use const.
In addition, const is to the commonly used.