1

I have already seen the following exmaple on it's usage:

#include <iostream> 
using namespace std; 

class A { 
public: 

    // A user-defined  
    // parameterized constructor 
    A(int x)  
    { 
        cout << "This is a parameterized constructor"; 
    } 

    // Using the default specifier to instruct 
    // the compiler to create the default  
    // implementation of the constructor. 
    A() = default;  
}; 

But to me A() = default; can simply be replaced with A() {}, an empty default constructor. I don't get the point of the default keyword here. Am I missing something?

Josh
  • 11
  • 2
  • `= default` is used to replace non-parametrized `A() {}` since C++11 to show it's a default constructor (nothing in the body) as strange as it may seem – J. S. May 03 '19 at 02:45
  • really? why?, i mean what's wrong with `A() {}` – Josh May 03 '19 at 02:50
  • 2
    https://stackoverflow.com/questions/20828907/the-new-keyword-default-in-c11 – Retired Ninja May 03 '19 at 02:53
  • There are actually a bunch of differences between `A(){}` and `A() = default;`. For one thing, `A(){}` blocks aggregate initialization and `A() = default;` doesn't. – user4581301 May 03 '19 at 03:02

0 Answers0