Programmer-Defined Types -- Examples
- Programmer Defined Types -- Example with structs
- Programmer Defined Types -- Example with classes
- Comparison of structs and classes
- In C++, there is very little actual difference between the struct
and the class. The only material difference is that a
struct has by default a public protection scheme. The
class has a private protection scheme by default.
However, in practice, C++ programmers tend to use structs as if
they only had the capabilities which the C language provides.
- Comparison of C and C++ structured type features
C
C++
- The struct name is not a type name
Struct names are also type names
- Components restricted to variables
Components of the class include both variable and member functions
- No protection scheme (public access) Three-level
protection scheme: public, protected and private
- No inheritance or polymorphism
Provides both inheritance and polymorphism