Introduction to C + + Classic-Example 7.9-Array of objects, batch production

Source: Internet
Author: User

1: In the contents of the array we learned that the array is a specified amount of content allocated by the pointer. Similarly, an array can contain objects. The Declaration object array is in the following form:

Box Boxarray[5];

Box Boxarray2[2]={box (1,1,1), Box (2,2,2)};

Box Boxarray3[3]={3,stylebox};

It is worth noting that the first method of applying an array of objects must ensure that the class contains the default good enough function, or the compiler will error. Similarly, you can request a dynamic array from an object pointer. For example:

box* box;

Pbox=new box[n];//n as an integer

You also need to confirm that the box contains a default constructor.

2: The code is as follows:

Introduction to C + + Classic-Example 7.9-Array of objects, batch production

Related Article

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.