   Quick questions about module design and a few misc.
  Hello,I have a few quick questions about module design and a few misc. other questions.Question 1)I am designing a math module.  The data fields of the math objects (CVector3 etc.) are accessible without accessors (they are public) but the objects also have overloaded operators and constructors etc.  So ... the question is ... are these technically structures or classes?  For example, would the following be SVector3 or CVector3?class CVector3 // or should this be a struct?{public:float x;float y;float z;public://constructors etc.//overloaded operators i.e. *,/,-/+, &lt;=, &gt;= etc.};[\code]Question 2)I am wondering what the default constructor should initialize the following mathematical objects to:Matrix = identity matrix or all 0's?Quaternion = all 0's or I have no idea?Plane = all 0's or I have no idea?Question 3)Ok, so in my design (see Question 1) there are methods to the objects that could potentially be added besides the overloaded operators and constructors.  I like the simplicity of going without, but obviously there are a lot of other methods that could be supplied.  For example Normalization of the vectors/planes/quaternions etc. or ... getting the vector length, length squared etc.  I am debating over adding the operations as methods to the objects or creating a separate math module to perform those type of non-operator methods as procedural programming functions performed &#111;n them.Route 1)  Keep the objects with &#111;nly data/constructors/operators and have a separate module that uses procedural programming functions to operate &#111;n them.  So ... you would have functions in that separate module such as:[code lang=C++]float GetVectorLength(const CVector3& vector);[\code]Pros:1) The interfaces to the objects are debatably cleaner and more simple.2) The objects are more compact.3) The method count &#111;n objects could very realistically get out of hand otherwise.Cons:2) You cannot call methods in the form vector.GetLength(); etc. and would have to call as GetVectorLength(vector); which is arguably not as tidy and potentially not as fast (passing values).Route 2)Add all the functions such as GetVectorLength as methods of the data objects.  Pros/Cons = see above.  In short, I am trying to have as neat an interface to this dilemna as possible and would appreciate any desing tips.Thank you for your help.Jeremy
  1) In C++ a struct is the same thing as a class, except that structs default to public access and inheritance and classes default to private access and inheritance.2) Your default constructor probably shouldn't set any of the members for those classes.3) In C++, when in doubt, use non-member non-friend functions. In this case you can also use namespaces to make things a little cleaner than prefixing all your functions with things like GetVector.   ;Quote:I am designing a math module.  The data fields of the math objects (CVector3 etc.) are accessible without accessors (they are public) but the objects also have overloaded operators and constructors etc.  So ... the question is ... are these technically structures or classes?  For example, would the following be SVector3 or CVector3?This is actually one of several good reasons not to add 'warts' (such as C or S) to your type names. Just name it (e.g.) Vector3; that way, you don't even have to worry about whether it's a class or a struct (a distinction that's more or less meaningless in C++ anyway, aside from convention and personal preference at least).Quote:I am wondering what the default constructor should initialize the following mathematical objects to:Matrix = identity matrix or all 0's?Quaternion = all 0's or I have no idea?Plane = all 0's or I have no idea?Many math libraries provide no default initialization for these types, following the principle that 'you shouldn't have to pay for what you don't use'. If you do want to provide default initializations however, I would say that in this particular context the following would be reasonable:Vector: zeroMatrix: identityQuaterion: identity (xyz = 0, w = 1)Plane: all zeros (which doesn't really mean anything, but any other choice would be arbitrary)   ;  If you do have naming warts, make sure they're consistent. One way I can think of doing this is that non-class structs are typically plain old data, so if you add overloaded operators go for the C- prefix.   