I always see constructors and destructors declared before anything else in a class. Is this just a nice coding standard that everyone uses to make it easier to find them or is there a reason behind it. For example, is there anything wrong with declaring a variable before the constructor like in the code below?
class A
{
public:
int aVar;
A() :aVar(20) {}
~A() {}
};
There’s no particular reason to declare constructors before everything else, it’s just a convention, or a coding practice. It’s like declaring public functions, then public members, then private functions, then private members, and order functions by alphabetical order.
The only ordering standard that has a reason is to not declare members by alphabetical order but by type size order, because it’s a simple way to have a smaller class.
Personally, I put enums and typedefs before the constructor and destructor.