C++ compilers diverge in encapsulation behavior – which one gets it right?

The questions of A::f<int>() and A::B<0> are straightforward to answer. f and B are private, and neither has any other interesting dependencies. Accessing them should be ill-formed. gcc generally is very permissive about access control in templates, there is a metabug outstanding for all sorts of situations (I think all of them are of the … Read more

accessing a protected member of a base class in another subclass

When foo receives a FooBase reference, the compiler doesn’t know whether the argument is a descendant of Foo, so it has to assume it’s not. Foo has access to inherited protected members of other Foo objects, not all other sibling classes. Consider this code: class FooSibling: public FooBase { }; FooSibling sib; Foo f; f.foo(sib); … 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

How to implement C# access modifiers in javascript?

I also had a similar thought and decided to try write something. A vanilla js solution. Still early but I like what came out of it. You might find it interesting also. It’s not exactly c# but provides a more strict ecosystem. And some other advanced js features in a lightweight solution. https://github.com/iamlothian/rucksack.js This is … Read more

What are the differences between the private keyword and private fields in TypeScript?

Private keyword The private keyword in TypeScript is a compile time annotation. It tells the compiler that a property should only be accessible inside that class: class PrivateKeywordClass { private value = 1; } const obj = new PrivateKeywordClass(); obj.value // compiler error: Property ‘value’ is private and only accessible within class ‘PrivateKeywordClass’. However compile … 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

What is encapsulation with simple example in php?

Encapsulation is just wrapping some data in an object. The term “encapsulation” is often used interchangeably with “information hiding”. Wikipedia has a pretty thorough article. Here’s an example from the first link in a Google search for ‘php encapsulation’: <?php class App { private static $_user; public function User( ) { if( $this->_user == null … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)