top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is special member functions in c++?

+1 vote
428 views
What is special member functions in c++?
posted Aug 3, 2017 by Robin Rj

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Special member functions

In C++ are functions which the compiler will automatically generate if they are used, but not declared explicitly by the programmer. The automatically generated special member functions are:

Default constructor: if no other constructor is explicitly declared.

Copy constructor: if no move constructor and move assignment operator are explicitly declared.
If a destructor is declared generation of a copy constructor is deprecated (C++11, proposal N3242 [2]).

Move constructor: if no copy constructor, copy assignment operator, move assignment operator and destructor are explicitly declared.

Copy assignment operator : if no move constructor and move assignment operator are explicitly declared.
If a destructor is declared generation of a copy assignment operator is deprecated.

Move assignment operator: if no copy constructor, copy assignment operator, move constructor and destructor are explicitly declared.

Destructor

Special member functions are member functions that are implicitly defined as member of classes under certain circumstances.

There are six:

Member function typical form for class C:
Default constructor C::C();
Destructor C::~C();
Copy constructor C::C (const C&);
Copy assignment C& operator= (const C&);
Move constructor C::C (C&&);
Move assignment C& operator= (C&&);

answer Aug 3, 2017 by Manikandan J
...