How to choose between private and protected access modifier to encapsulate members between base and childs classes?

Why don’t I have an error message, when I set ID value in daughter class, the sentence this.id=value is executed, but how can can I access to it from my child class if it is private? When you call a public method on a class, that method can access private members of that class: public … Read more

Effective C++ Item 23 Prefer non-member non-friend functions to member functions

Access to the book is by no mean necessary. The issues we are dealing here are Dependency and Reuse. In a well-designed software, you try to isolate items from one another so as to reduce Dependencies, because Dependencies are a hurdle to overcome when change is necessary. In a well-designed software, you apply the DRY … Read more

Properties vs. Fields: Need help grasping the uses of Properties over Fields

1) why I would want to use properties instead of fields (especially when it appears I am just adding additional code You should always use properties where possible. They abstract direct access to the field (which is created for you if you don’t create one). Even if the property does nothing other than setting a … Read more

Abstraction VS Information Hiding VS Encapsulation

Go to the source! Grady Booch says (in Object Oriented Analysis and Design, page 49, second edition): Abstraction and encapsulation are complementary concepts: abstraction focuses on the observable behavior of an object… encapsulation focuses upon the implementation that gives rise to this behavior… encapsulation is most often achieved through information hiding, which is the process … Read more

Can I access private members from outside the class without using friends?

If the class contains any template member functions you can specialize that member function to suit your needs. Even if the original developer didn’t think of it. safe.h class safe { int money; public: safe() : money(1000000) { } template <typename T> void backdoor() { // Do some stuff. } }; main.cpp: #include <safe.h> #include … Read more

tech