Class default access modifier
In a class, the default access modifier for class member and member functions is private.
Private members are the class members (data members and member functions) that are hidden from the outside world. The private members implement the concept of OOP called data hiding.
Class default access (private)
The above program can not compile since all default access modifier are private.
$ g++ class.cpp class.cpp:19:13: error: calling a private constructor of class 'student' s1 = new student(); ^ class.cpp:4:4: note: implicitly declared private here student(); ^ class.cpp:20:7: error: 'm_Member1' is a private member of 'student' s1->m_Member1 = 0; ^ class.cpp:3:7: note: implicitly declared private here int m_Member1; ^ class.cpp:21:10: error: calling a private destructor of class 'student' delete s1; ^ class.cpp:5:4: note: implicitly declared private here ~student(); ^ 3 errors generated. $
Class default access override with "public"
Having "public" access can pass the compilation.
About our authors: Team EQA
You have viewed 1 page out of 62. Your C++ learning is 0.00% complete. Login to check your learning progress.
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Draw on printer Memory leaks Best Hosting plans, 80% discounts