C + + generates 4 member functions by default.
Default constructor (constructor), destructor (destructor), copy constructor (copy constructor), Assignment function (Assignment);
Where the destructor, the basic type data for C + + is automatically destructor.
"=default" means that the default is added and can be used for overloading; "=delete" means delete, that is, default is not used;
The following code mainly shows the generation of copy constructors and assignment functions.
Code:
* * * test.cpp * * Created on:2014.04.14 *
author:spike/
/*eclipse CDT, gcc 4.8.1* /
#include <iostream>
#include <string>
using namespace std;
class Foo {public
:
foo (std::string _name): M_name (_name) {};
void Say () {std::cout << m_name << Std::endl;}
Foo (const foo&) = default; Delete indicates deletion, default
foo& operator= (const foo&) = defaults;
~foo () = default;
Private:
std::string m_name;
int main () {
Foo F1 ("Wang");
Foo F2 (F1);
Foo F3 = F2;
F2.say ();
F3.say ();
return 0;
}
Output:
Wang
Wang
Author: csdn Blog spike_king
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/cplus/