Class Object Array

Source: Internet
Author: User

The Class Object array is defined in the same way as the built-in type array, for example
Account table [16];
Defines an array containing 16 account objects, and each element uses the default account to construct the initial function.
If you like, you can use the initialization table in parentheses to provide explicit real parameters for the constructor, for example
Account pooh_pals [] = {"Piglet", "Eeyore", "Tigger "};
An array that defines three elements.
Account ("Piglet", 0.0); // The first element
Account ("Eeyore", 0.0); // second element
Account ("Tigger", 0.0); // The third element
Initialization
A single real parameter of the constructor can be explicitly specified as shown in the preceding example.
Real parameters, you need to use the complete constructor syntax, such
Account pooh_pals [] = {
Account ("Piglet", 1000.0 ),
Account ("Eeyore", 1000.0 ),
Account ("Tigger", 1000.0)
};

 

If you want to specify the default constructor in the array initialization table, we can use the complete structure with an empty parameter table.
Function syntax example
Account pooh_pols [] = {
Account ("Woozle", 10.0 ),
Account ("heffalump", 10.0 ),
Account ()
};
We can also obtain the equivalent array of the three elements as follows:
Account pooh_pols [3] = {
Account ("Woozle", 10.0 ),
Account ("heffalump", 10.0)
};

====================

// Indicates that pact points to an array
Delete [] Pact;
Empty Square brackets indicate that pact points to an array compiler and obtains the number of elements in the array. This ensures that the Destructor is applied to each element.

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.