<<< C++ struct initialization | Index | >>> |
Constructors provide support for multiple ways of object creation and initialization.
Constructor is a special member function.
Every declaration of an object results in the calling of a constructor.
How are constructors defined?
struct Rectangle { int width; // member variable int height; // member variable // C++ constructors Rectangle() { width = 1; height = 1; } Rectangle( int width_ ) { width = width_; height = width_ ; } Rectangle( int width_ , int height_ ) { width = width_; height = height_; } // ... };
<<< C++ struct initialization | Index | >>> |