-
Struct and class
Is it conventional to use both structs and classes in c++?i recall abachler saying he used struct for objects without member functions,i like this idea as providing clarity while working, to distinguish a complex data type from an object that 'does' things but is this valid c++?
-
Yes, it is often a convention to use both, but for slightly different purposes. As for valid C++: duh. You can write object oriented C++ and have fun with class templates without ever using the class keyword.
-
I think it is but some disagree with me. My personal policy is this:
1. A struct cannot have methods, but may have a constructor in order to initialize data. A struct should not encapsulate any functionality.
2. A class must encapsulate some type of functionality. If a class merely wraps access to variables - IE: is only composed of accessors and mutators - then it should most likely be a struct.