C++ class design question - static member
-
Hi I am currently building an app that maintains a number of objects of a certain class, and the app performs computationally heavy calculations to determine the state of each object. The state for each object is determined by a number of variables: e.g. variables A, B, C, and D. However, since some of the variables, e.g. variable A is actually identical for all objects, I am now implementing A as a private static variable with a public accessor function. This way, I think I can save some computation and storage space. My question is: is this the correct way to implement the class? Is building a base class and deriving from it better than my current solution? Thanks!
-
Hi I am currently building an app that maintains a number of objects of a certain class, and the app performs computationally heavy calculations to determine the state of each object. The state for each object is determined by a number of variables: e.g. variables A, B, C, and D. However, since some of the variables, e.g. variable A is actually identical for all objects, I am now implementing A as a private static variable with a public accessor function. This way, I think I can save some computation and storage space. My question is: is this the correct way to implement the class? Is building a base class and deriving from it better than my current solution? Thanks!
hi indrawati, in your case, the important thing is that what do your variables do. if there are required to be common for all the objects of the particular class, ie they share the same values, then u will have to use them as static. if this is the case then there should be no problem in the design