C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
The new Operator
                                             Up Contents Index Back
─────C/C++ Language─────────────────────────────────────────────────────────
 
  Keyword:  new
 
  Syntax:   [::] new [model] [placement] type-name [initializer]
            [::] new [model] [placement] ( type-name ) [initializer]
 
  Summary:  Allocates memory for an object of <type-name> from the
            free store and returns a suitably typed, nonzero pointer to
            an object. If unsuccessful, new returns zero.
 
            Use the delete operator to deallocate the memory allocated
            with the new operator.
 
  See also: delete, _set_new_handler
            __near, __far, __huge, __based
            Memory Models
            Customizing the New Operator
 
     The following describes the elements of new:
 
     Element              Description
 
     <placement>          Provides a way of passing additional
                          arguments if you overload new.
                          See: Customizing the New Operator
 
     <type-name>          Specifies type to be allocated. If the
                          type specification is complicated, it can
                          be surrounded by parentheses to force the
                          order of binding.
 
     <model>              Specifies the addressing mode of the
                          returned pointer. Can be __near, __far,
                          __huge, or __based(<segment-expression>).
                          When you specify one of these pointer
                          types to new, you must use the same
                          version of the delete operator.
 
     <initializer>        Provides a value for the initialized
                          object. Initializers cannot be
                          specified for arrays. The new operator
                          will create arrays of objects only if
                          the class has a default constructor.
 
     This statement allocates an integer.
 
          int *pi = new int;
 
     This statement allocates a character and initializes it.
 
          char *pc = new char( 'a' );
 
     This statement allocates an instance of Date using the class's
     three-argument constructor, and returns a far pointer to it.
 
          Date *pmc = new __far Date( 3, 12, 1985 );
 
     This statement allocates an array of characters.
 
          char *pstr = new char[sizeof( str )];
 
     This statement allocates a two-dimensional array of
     characters of size dim * 10. When allocating a multi-
     dimensional array, all dimensions except the first must
     be constant expressions.
 
          char (*pchar)[10] = new char[dim][10];
 
     This statement allocates an array of seven pointers to
     functions that return integers.
 
          int (**p) () = new (int (*[7]) ());
                                    -♦-