Download presentation
Presentation is loading. Please wait.
Published byAllen Stevens Modified over 8 years ago
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.