External Declarations and Definitions

From RAD Studio
Jump to: navigation, search

Go Up to Declaration Syntax Index

The storage class specifiers auto and register cannot appear in an external declaration. For each identifier in a translation unit declared with internal linkage, no more than one external definition can be given.

An external definition is an external declaration that also defines an object or function; that is, it also allocates storage. If an identifier declared with external linkage is used in an expression (other than as part of the operand of sizeof), then exactly one external definition of that identifier must exist in the entire program.

The C++ compiler allows later declarations of external names, such as arrays, structures, and unions, to add information to earlier declarations. Here's an example:

int a[];              // no size
struct mystruct;      // tag only, no member declarators
  .
  .
  .
int a[3] = {1, 2, 3}; // supply size and initialize
struct mystruct {
   int i, j;
};                    // add member declarators

The following syntax diagram covers class declaration syntax. In the section on classes (beginning with Classes), you can find examples of how to declare a class. Lvalue References covers C++ lvalue reference types (closely related to pointer types) in detail. Finally, see Using Templates (C++) for a discussion of template-type classes.

C++Builder class declaration syntax (C++ only)

class-specifier:                                   
  class-head { <member-list> }                       
class-head:                                          
  class-key <identifier> <base-specifier>          
  class-key class-name <base-specifier>            
member-list:                                        
  member-declaration <member-list>                     
  access-specifier : <member-list>                     
member-declaration:                                     
  <decl-specifiers> <member-declarator-list>;      
  function-definition <;>                          
  qualified-name ;                                
member-declarator-list:                              
  member-declarator                                
  member-declarator-list, member-declarator        
member-declarator:                                 
  declarator <pure-specifier>                 
  <identifier> : constant-expression            
pure-specifier:                                  
  = 0                                     
member-initializer-list:                           
  member-initializer                                  
  member-initializer , member-initializer-list       
member-initializer:                                   
  class-name ( <argument-list> )                     
  identifier ( <argument-list> )                     
operator-function-name:                                 
  operator operator-name                            
base-specifier:
  : base-list
  class-name 
  virtual <access-specifier> class-name
  access-specifier <virtual> class-name
base-list:
  base-specifier
  base-list , base-specifier
access-specifier:
  private
  protected
  public                                                       
conversion-function-name:
   operator conversion-type-name
conversion-type-name:
  type-specifiers <pointer-operator>
constructor-initializer:
  :member-initializer-list
operator-name: one of
  new delete sizeof typeid
  +  -  *  /  %  ^
  &  |  ~  !  =  <>
  +=  -=  =*  /=  %=  ^=
  &=  |=  <<  >>  >>=  <<=
  ==  !=  <=  >=  &&  ||
  ++  __  ,  ->*  ->  ()
  [ ]  .*

See Also