What is the purpose of declaring multiple "public" specifiers over and over again when the next line is just right below it, or few lines below it. I can understand this is requirement when the codes modified the attribute of some identifiers, i.e., those that are buried within a macro (hence changing the access attributes within the macro, so we need to "redefined" coming out of the macro), or when we have many identifiers per access specifier section. But what is the purpose of keep using "public", "public", over and over again?
Code ...
class CDrawMFCView : public CView
{
protected: // create from serialization only
CDrawMFCView();
DECLARE_DYNCREATE(CDrawMFCView)
// Attributes
public:
CDrawMFCDoc* GetDocument() const;
// Operations
public:
// Overrides
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
// etc.,
};
For starters, it's not necessary for how the code is NOW, it's necessary because the code sections may:
If you relied the section having the same access specification as the previous section, very very often you (or you, six months from now, or someone else) would forget to change it when the code changed, and then the code would be wrong.
It could be useful when looking at a class with more methods than lines on your screen, so you just look at, say
...
void f();
void g();
void h();
...
By repeating public:
a few times you could remind people that all these are public (of course, having more methods than lines in your terminal either means your terminal is a bit small or the class is too big).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With