Thinking about C + + functions 1 (the default six major functions)

Source: Internet
Author: User

we know that the great gods have six default functions for C + + when designing C + +, so the default is that you do not have to write to our programmers, as long as you instantiate the class, create an object, and the compiler calls the default function automatically when you manipulate the object for data manipulation. But the default function is not what C + + wants us to use, the really powerful is that we on these default foundation, our own DIY function to implement the default function can not do and it will do, only in this way can the ability to greatly increase. Here are some of the thoughts I have when writing C + + functions:

The six default functions are in turn:

<pre name= "code" class= "CPP" >/**********************************************************************    * *   Copyright (c) 2015,wk Studios  * *   Filename:  str.h * *   COMPILER:GCC  VC 6.0   * *   Author : WK    * *   time:2015 5  * **********************************************************************/ Class s{public:s (int i=0,double n=0): M_data (i), data (n) {cout<< this<< "\ n"; Private:int m_data;    Double data;}; int main () {S s0;//1//  This is when we customize the constructor compiler to no longer call the default parameterless constructor,          //If you want to do this, you must customize an parameterless constructor, or customize the default constructor,         // As in the above function, that is, if there is a default value, it will be an error, because the corresponding constructor is not found S (10.8);//2s; 3S ((int) 10.8);//4s SS (10,20);//5s ss1 (10.8);//6s SS2 ((int) 10.8);//7s s (10,10.8);//8  //Call constructor S s22= (10,10.8) ;//9s S1 = (10,10.8);//10

C + + Six default functions//When used, those functions are transparent, that is, those functions learned a trick stealth technology AH hahaha AH class default{public:/* default () {}//default constructor defaults (const default &) {}//copy constructor ~default () {}//destructor default& operator= (const default&) {}//assignment operator default* operator& () {}// Accessor operator Const default* operator& () const{}//accessor operator Const*/private:int m_data; };int Main () {default t;//call constructor default T1=t;//default T1 (t);//Call copy constructor default t2;t2=t;//Call assignment function Default *pt = &t;//tune Use the value function const default T3;const default *PT1 = &t3;//call the const accessor//Call destructor return 0;}

The power of C + + is not that there are many default encapsulation methods, but rather the greatest creation space given to programmers on the basis of satisfying these basic functions. These default functions can only guarantee the normal mode of C + +, on this basis there is a great deal of interface space to design and implement methods

1. We look at a program





Thinking about C + + functions 1 (the default six major functions)

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.