Skip Navigation Links | |
Exit Print View | |
Oracle Solaris Studio 12.3: C++ User's Guide Oracle Solaris Studio 12.3 Information Library |
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.8 Passing the Address of an Anonymous Class Instance
4.10 Using the Predefined __func__ Symbol for Function Name
4.11.1 __packed__ Attribute Details
4.12 Compiler Support for Intel MMX and Extended x86 Platform Intrinsics
6. Creating and Using Templates
9. Improving Program Performance
10. Building Multithreaded Programs
12. Using the C++ Standard Library
The following code is invalid.
class A { friend static void foo(<args>); ... };
Because a class name has external linkage and all definitions must be identical, friend functions must also have external linkage. However, when you use the -features=extensions option, the compiler to accepts this code.
Presumably the programmer’s intent with this invalid code was to provide a nonmember “helper” function in the implementation file for class A. You can get the same effect by making foo a static member function. You can make it private if you do not want clients to call the function.
Note - If you use this extension, your class can be “hijacked” by any client. Any client can include the class header, then define its own static function foo, which will automatically be a friend of the class. The effect will be as if you made all members of the class public.