C + + Empty class detailed _c language

Source: Internet
Author: User

Null class Default-generated members:
Class Empty {};
Empty (); Default constructor
Empty (const empty&); Default copy constructor
~empty (); Default destructor
empty& operator= (const empty&); Default assignment operator
empty* operator& (); Fetch operator
Const empty* operator& () const; Address operator Const

Give an example:

Copy Code code as follows:

#include <iostream>
using namespace Std;

Class Empty
{
Public
Empty *operator& ()
{
cout<< "AAAA" <<endl;
return this;
}
Const empty* operator& () const
{
cout<< "BBBB" <<endl;
return this;
}
};

int main (void)
{
Empty e;
Empty *p=&e;
Const EMPTY E2;
Const Empty *p2=&e2;
Cout<<sizeof (Empty) <<endl;
}


Run Result:




Visible:
Empty *p=&e called the empty* operator& () operator function
The const empty* operator& () const operator function is invoked by the const Empty *P2=&E2.
The size of the empty class is 1 bytes.

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.