...
- Examples
Let's see examples of how the 'default' and 'delete' keywords can be used to our benefit.
default
#include <iostream>class SomeType{ public: // state the compiler generated default constructor SomeType() = default; // constructor for int SomeType(int value){ std::cout << "SomeType(int) " << std::endl; }; // explicit Copy Constructor explicit SomeType(const SomeType&) = default; // virtual destructor virtual ~SomeType() = default;};int main(){ std::cout << std::endl; SomeType someType; SomeType someType2(2); SomeType someType3(someType2); std::cout << std::endl;}
In this example, we can see how default can be used to get the default implementations of constructors and destructors from the compiler.
Since we have defined a parameterized constructor in line 10, ...