Tag: Constant thinkinginc++ in the class during compilation;
/*** book: "thinkinginc++" * Function: Constants in class during compilation * Time: September 10, 2014 08:32:56* Author: cutter_point*/#include <cstring> #include < Iostream>using namespace Std;class stringstack{static const int size=100; All objects are shared and unchanging Data const string* Stack[size]; int Index;public:stringstack (); void push (const string* s); Const string* pop ();}; Stringstack::stringstack (): Index (0) {//included in the CString header file (c + +) and in C is the String.h (c) header file//plus a. h represents the inclusion of the using namespace Std; memset (Stack, 0, size*sizeof (string*)); The array stack initializes all}void StringStack::p ush (const string* s) {if (Index < size) stack[index++]=s;} Const string* StringStack::p op () {if (Index > 0) {const string* Rv=stack[--index]; initialization, where const is used to return a value of stack[index]=0; return RV; Return to function} return 0;} String icecream[]={"Pralines & Cream", "Fudge Ripple", "Cutter_point", "Wild Mountain BlackBerry", "Ra Spberry sorbet "," Lemon Swirl "," Rocky Road "," Deep chocolate fudge "};coNST int icsz=sizeof (icecream)/sizeof (*icecream); The number of strings inside the icecream is calculated int main () {StringStack ss; for (int i=0; i<icsz; ++i)//void push (const string* s); Ss.push (&icecream[i]); Const string* CP; while ((Cp=ss.pop ())! = 0) cout<<*cp<<endl; return 0;}
"Thinkinginc++" 44, constants in the class during compilation