C ++ basic static member, destructor display call textbook 5.1

Source: Internet
Author: User
// ================================================ ==================================================================== // Name: 5.1.cpp // Author: Zhaoming // version: // copyright: copyright to Zhaoming // Description: Hello world in C ++, ANSI-style // ========================================== ========================================================== = // In C ++, 5.1 is incorrect. # include <iostream> using namespace STD; class list {int value; list * Next; static list * head; // declare the static data member public: List (INT value );~ List () ;}; list * List: Head = 0; // defines and initializes the static data member list: List (INT v) {value = V; next = head; head = This;} List ::~ List () {list * P = head; If (Head = This) {head = This-> next;} else {While (p-> next! = NULL & P-> next! = This) // When the second destructor of B is called, P is null. P = p-> next; P-> next = This-> next;} cout <"<this-> value <" ";}int main () {List A (1); List B (2); List C (3); // B. ~ List (); // After the call is displayed, it will be called once by default, resulting in an error Return 0 ;}

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.