I am looking for some code in a company on which I am currently working and I have some (not much) Fixed global variables (for example, to store list of listeners) in announcements * .cpp files where
.h / .cpp files belong to a class. If a variable (steady or otherwise) is used only in class, then I always declare it as private
Is there any advantage to declare it private? Is this bad behavior? Or is it normal when just declaring static variables used by class and nobody else?
Edit: In my question I asked about the stable, but if it is a non-static global variable instead of being a private member of the class instead of .pppp < / Code> in the file? Is it bad behavior or is it considered okay? Any advantage in this matter?
In this way, the main benefit amount is decreasing * .h in the file " Unnecessary "stuff can compile some time and modify / modify files when the complexity is improved again, and it can make the header file a little easier to read.
(In my opinion, these advantages are small, and I usually have the clarity of putting those sections which are logically related to a class within the scope of that class.)
However, static global variables are disliked and poor behavior in C ++ if there is no other appropriate area, an unknown namespace should be used.
// Instead: Fixed std :: list & lt; MyClass * & gt; MyClass_population; // do this: namespace {// anonymous std :: list & lt; MyClass * & gt; MyClass_population; }
Comments
Post a Comment