I was looking through some open source code and found a class declaration like this:
class Foo{
private:
// declarations
private:
// declarations
private:
// declarations
public:
// declarations
};
Is there any time you would want to do such a thing, except to remind you of the members' privacy when having a very long list of declarations?
This is particularly useful for this type of scenario:
class SomeClass
{
// COnstructors etc.
public:
SomeClass();
SomeClass(const SomeClass& other);
~SomeClass();
SomeClass operator=(const SomeClass& other);
SomeClass(const OtherClass& other);
// Internal use functions.
private:
int SomePrivateFunc();
int OtherPrivateFunc();
// Functions that "do stuff" with this class.
public:
int SomeFunc();
int OtherFunc();
// Private member variables.
private:
int x, y;
// Public member variables.
public:
int value;
}
(The comments like // Constructurs etc.
are just there to show that this is a section of "these things belong together")
Yes you can do this to remember members privacy, but also to separate your class's data types, attributes and methods, etc...
It is not wrong, and you could be right, it could be a reminder, semantically is the same as using it only once. In my view (and use) using one section more than once can confuse and mislead readers, not saying that a stronger reminder is using comments, specially for structure members into groups.
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