Article 19: Design class like design type

Source: Internet
Author: User

1, how should the new type object be created and destroyed?

This affects the class's constructor ctor and Destructor Dtor, as well as memory allocation functions and deallocation functions

operator NEW

Operator New[]

operator delete

Operator Delete[]

2, what is the difference between the initialization of an object and the assignment of an object?

Initialization is in the constructor ctor

The assignment of an object is the assigment operator//operator =

3, what does the object of the new type mean if it is passed by value?

means a copy construction process is generated,//operator ()

4, what is the legal value of the new type?

Usually only certain function value sets are valid. Then your class must maintain the constraints that determine your member functions (especially ctor and copy constructors, setter functions) need to be checked for errors.

5, does the new type need to match an inheritance graph?

Is whether to declare that a function is virtual? Especially if Dtor is virtual?

6, what kind of conversion does the new type require?

If you allow T1 to be implicitly converted to T2, you need to write a type conversion function//operator T2 within T1,

Or a constructor that writes a non-explicit-one-argument (which can be called by a single argument) within class T2.

If you need to display the conversion, you need to write a special conversion function, and can not be any of the above 2 implicit methods;

7, what kind of standard function should be forbidden?

Declare as Private

8, do you offer generalization?

Template

Article 19: Design class like design type

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.