Constructors and Destructors |
|
This isn't necessarily a pitfall, but it is certainly worth mentioning that although class (and structure) constructors and destructors are functions, they are quite different from any other function and you should know the difference. Here is a list of interesting points about these two special types of functions. 1. Neither constructors nor destructors have return types (not even void). 2. A destructor cannot take arguments (not even void). 3. A destructor cannot be overloaded. 4. Both constructors and destructors are called implicitly, so you never need to call them yourself. 5. Constructors cannot be declared virtual. 6. Both constructors and destructors must have the same name as its class (structure), except a destructor has a tilde (~) in front of it. 7. Even if you don't explicitly write a constructor and destructor for a class, the compiler will write default ones for you (because a class must have both). |
|
This page is best viewed in 800x600x256. This page was last edited Saturday, July 15, 2000 |