What does the “private” modifier do?

There’s a certain amount of misinformation here: “The default access modifier is not private but internal” Well, that depends on what you’re talking about. For members of a type, it’s private. For top-level types themselves, it’s internal. “Private is only the default for methods on a type” No, it’s the default for all members of … Read more

C++ Private Structures

Yes structures can have private members, you just need to use the access specifier for the same. struct Mystruct { private: m_data; }; Only difference between structure and class are: access specifier defaults to private for class and public for struct inheritance defaults to private for class and public for struct How can you access … Read more

Eslint does not recognize private field declaration using nodejs 12

2021 Update: You do not need babel for this anymore! You can simply update eslint to v8.0.0 and above. See eslint release notes: https://eslint.org/blog/2021/10/eslint-v8.0.0-released#highlights Make sure this is in your .eslintrc file or similar: { “parserOptions”: { “ecmaVersion”: 13 } } You can also just use latest instead of specifically version 13.

Pylint W0212 protected-access

pylint doesn’t know of which type other is (how should it, you can compare an instance of A to everything), therefore the warning. I don’t think there is a way around disabling the warning. You can disable the warning for only that one line with appending # pylint: disable=W0212 to that line.

Why make private inner class member public in Java?

If the InnerEvenIterator class does not extend any class or implement any interface, I think it is nonsense because no other class can access any instance of it. However, if it extends or implements any other non private class or interface, it makes sense. An example: interface EvenIterator { public boolean hasNext(); } public class … Read more

Mechanism to check if a C++ member is private

If you want to assert that a type Bar doesn’t have a public member named foo, you can write the following test: template<typename T> constexpr auto has_public_foo(T const &t) -> decltype(t.foo, true) { return true; } constexpr auto has_public_foo(…) { return false; } static_assert(not has_public_foo(Bar{}), “Public members are bad practice”); Here’s a demo.

How to write a simple class in C++?

Well documented example taken and explained better from Constructors and Destructors in C++: #include <iostream> // for cout and cin class Cat // begin declaration of the class { public: // begin public section Cat(int initialAge); // constructor Cat(const Cat& copy_from); //copy constructor Cat& operator=(const Cat& copy_from); //copy assignment ~Cat(); // destructor int GetAge() const; … Read more

How to make instance variables private in Ruby?

Like most things in Ruby, instance variables aren’t truly “private” and can be accessed by anyone with d.instance_variable_get :@x. Unlike in Java/C++, though, instance variables in Ruby are always private. They are never part of the public API like methods are, since they can only be accessed with that verbose getter. So if there’s any … Read more

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