+ 1
C++ Class Constructors and Destructors Access Specifiers
Hello, I notice that when I define a default constructor under private: in a class, it does not execute, but when I put a destructor under private, it produces an error when I declare a variable of type class. Why is that? https://code.sololearn.com/cc4txYWRo0yU/#cpp
3 ответов
+ 4
Because when you put a constructor inside the private section of the class, default constructor gets executed instead of the one defined by you.
Whereas in the case of destructors, you can't have more than one for a class thus as and when you define one as private, object can no longer access it, and hence generate an error.
+ 2
Your welcome Edward Finkelstein 🙂
+ 1
thank you Arsenic