"Thinkinginc++" 44, constants in the class during compilation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.