Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX 0.075 //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis"

Similar presentations


Presentation on theme: "1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX 0.075 //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis""— Presentation transcript:

1 1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX 0.075 //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis" #define GO #define SKIP void main() { cout << FIRST_NAME << " " << LAST_NAME << endl; cout << "TAX = " << TAX << endl; #ifdef GO cout << "GO\n"; cout << "and GO\n"; #endif #ifndef SKIP cout << "NO SKIP\n"; #endif cout << endl; }

2 2 Compiler directive: #define, usage 2 #define now_define_add(type)\ type add(type a, type b)\ { return a+b; }\ now_define_add(int) now_define_add(double) void main() { int a=1,b=2; double r=1, s=2; cout << a / add(a,b) << endl; cout << a / add(r,s) << endl; } continue to the next line

3 3 Name space: A pace for definitions. i.e., variables and function definition. #include using namespace std; namespace room201 { char *instructor = "Osborne"; char *teach() { return "NetWorking"; } namespace room69 { char *instructor = "Li"; char *teach() { return "Cryptography"; }

4 4 Using Name space (1): Tell in which room.. #include using namespace std; namespace room201 {...} namespace room69 {...} void main() { cout << room201::instructor << " teaches " << room201::teach() << endl; cout << room69::instructor << " teaches " << room69::teach() << endl;.... } Osborne teaches NetWorking Li teaches Cryptography

5 5 Using Name space (2): Tell which room to use.. #include using namespace std; namespace room201 {...} namespace room69 {...} void main() {...... { using namespace room201; cout << instructor << " teaches "; cout << teach() << endl; } using namespace room69; cout << instructor << " teaches " << teach() << endl; } Osborne teaches NetWorking Li teaches Cryptography


Download ppt "1 Compiler directive: #define, usage 1 #include using namespace std; #define TAX 0.075 //double TAX=0.08; #define LAST_NAME "Li" #define FIRST_NAME "Dennis""

Similar presentations


Ads by Google