C++20 sections · 1024 units
Open in Course

Constructor Overloading

Multiple constructors

You can define several constructors with different parameter lists. One might take no arguments, another takes two integers, another takes a string. The compiler chooses which to call based on how you create the object.

This gives users flexible initialization options. They can write Point p; for a default origin or Point p(3, 5); for a custom location. Each constructor version can initialize members differently, but they all ensure the object starts in a valid state.