dimanche 1 mars 2015

C++ Special member functions

I have always known that special member functions of C++ are:



  • Default constructor

  • Copy Constructor

  • Copy assignment operator

  • Destructor

  • Move constructor

  • Move assignment operator


Now I am reading Mayer’s Effective C++ book and have realized that there is also pair of address-of operators.


I can redefine it this way:



class A
{
public:
A* operator&()
{
std::cout << "Address of operator" << std::endl;
}
};

int main()
{
A a;
B* b = &a; // Will call address-of operator.
}


Why then in C++ standard section 12 (Special member functions) there is no word about this operator. This is also common question in C++ interviews.


Aucun commentaire:

Enregistrer un commentaire