If a book about C++ tells you that you cannot use private member variables from another class, just throw the book away. Real Programmers, when they are forced to use C++, start their programs with the following line, before including any header file, and they never have OOP headaches:

   #define private public

Never underestimate the power of C++.

Easy. Even a stubborn C programmer like myself knows that the default mode in class definitions is private:. Just write your code like this...
  class C {
    // this is all private:
    int cantTouchThis;
    // ...

BC++PFHs would be advised to #define class struct, just in case.

At the top of the code? Not needed.

    -Dprivate=public -Dprotected=public -Dclass=struct

In your compiler's command line. Oh, yes, and I added "protected" too, you forgot that one. Of course, we all know this is bad practice.

#define private public is, strictly speaking, illegal. Section of the C++ Standard states that "Nor shall such a translation unit define macros for names lexically identical to keywords." -- which means that an implementation would be permitted, if it so desired, to reject programs attempting the definition.

This would probably be no bad thing, though I'm not aware of any compiler (or preprocessor) that attempts to enforce this rule.

Log in or register to write something here or to contact authors.