- Examples
Let's see examples of how the 'default' and 'delete' keywords can be used to our benefit.
We'll cover the following...
Constructors and destructors using default
#
Press + to interact
#include <iostream>class SomeType{public:// state the compiler generated default constructorSomeType() = default;// constructor for intSomeType(int value){std::cout << "SomeType(int) " << std::endl;};// explicit Copy Constructorexplicit SomeType(const SomeType&) = default;// virtual destructorvirtual ~SomeType() = default;};int main(){std::cout << std::endl;SomeType someType;SomeType someType2(2);SomeType someType3(someType2);std::cout << std::endl;}
Explanation #
-
In this example, we can see how
default
can be ...