-6

We know that encapsulation binds the data members and member functions into a bounded scope.Now anyone who has to make changes to the data(for eg. private data) has to get into the scope of the class.So when we talk about data hiding, can we say that SCOPE OF PUBLIC MEMBERS IS GLOBAL?,as they can be accessed anywhere. If yes,then isn't it that it violates the rule of encapsulation(in which scope is bounded)?

geeky_guy
  • 21
  • 3
  • What does this have to do with either C++ or C? – UnholySheep Apr 22 '17 at 18:25
  • Globally-accessible doesn't imply global scope. `public` members are visible to the outside world, so they can be considered globally accessible. However, they are still within the containing class' scope, so they aren't in the global scope. It's the same way with members of a namespace; `std::vector` is globally accessible, assuming the header is `#include`d, but it's in the `std` scope instead of the global one. – Justin Time - Reinstate Monica Apr 22 '17 at 21:39

1 Answers1

1

A public member isn't global if it isn't also static, for access to a (non static) public member you need to create an object of that class so that don't break the concept of encapsulation.

Helio
  • 193
  • 2
  • 11