dimanche 23 septembre 2018

Why does uniform initialization work even when the default constructor is deleted? [duplicate]

This question already has an answer here:

#include <iostream>                                                             

class trial {                                                                      
public:                                                                        
    trial() = delete;                                                          

    void print() {                                                             
        std::cout << "a" << std::endl;                                         
    }                       
};       

int main() {                                                                       
   trial a{};                                                                     
   a.print();                                                                     
   return 0;                                                                       
}     

Could someone please explain why this piece of code works whereas when

trial a = trial();

is used it doesn't?

Aucun commentaire:

Enregistrer un commentaire