RAD Studio |  |

Overloading Constructors
See Also
Collapse All

Constructors can be overloaded, allowing objects to be created, depending on the values being used for initialization.

Copy Code

    class X {
       int    integer_part;
       double double_part;
    public:
       X(int i)    { integer_part = i; }
       X(double d) { double_part = d; }
    };
    int main()
    {
       X one(10);   // invokes X::X(int) and sets integer_part to 10
       X one(3.14); // invokes X::X(double) setting double_part to 3.14
       return 0;
    }

See Also

Class Initialization

Invoking Destructors

Atexit

Exit And Destructors

abort And Destructors

Virtual Destructors

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!