3. Using the C++ Compiler Options
4.1.1 Compatibility with Microsoft Windows
4.3 Overriding With Less Restrictive Virtual Functions
4.4 Making Forward Declarations of enum Types and Variables
4.5 Using Incomplete enum Types
4.6 Using an enum Name as a Scope Qualifier
4.7 Using Anonymous struct Declarations
4.9 Declaring a Static Namespace-Scope Function as a Class Friend
4.10 Using the Predefined __func__ Symbol for Function Name
6. Creating and Using Templates
9. Improving Program Performance
10. Building Multithreaded Programs
12. Using The C++ Standard Library
13. Using the Classic iostream Library
You are not allowed to take the address of a temporary variable. For example, the following code is invalid because it takes the address of a variable created by a constructor call. However, the compiler accepts this invalid code when you use the -features=extensions option.
class C { public: C(int); ... }; void f1(C*); int main() { f1(&C(2)); // invalid }
Note that you can make this code valid by using an explicit variable.
C c(2); f1(&c);
The temporary object is destroyed when the function returns. Ensuring that the address of the temporary variable is not retained is the programmer’s responsibility. In addition, the data that is stored in the temporary variable (for example, by f1) is lost when the temporary variable is destroyed.