Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 06:42, 4 May 2007.

New

From Forum Nokia Wiki

The new operator provides dynamic storage allocation. The syntax for an allocation expression containing the new operator is:

>>-+----+--new--+---------------------+--+-(--type--)-+--------->
   '-::-'       '-(--argument_list--)-'  '-new_type---'
 
>--+-------------------------+---------------------------------><
   '-(--+---------------+--)-'
        '-initial_value-'

If you prefix new with the scope resolution operator (::), the global operator new() is used. If you specify an argument_list, the overloaded new operator that corresponds to that argument_list is used. The type is an existing built-in or user-defined type. A new_type is a type that has not already been defined and can include type specifiers and declarators.

An allocation expression containing the new operator is used to find storage in free store for the object being created. The new expression returns a pointer to the object created and can be used to initialize the object. If the object is an array, a pointer to the initial element is returned.

You can use set_new_handler() only to specify what new does when it fails.

You cannot use the new operator to allocate function types, void, or incomplete class types because these are not object types. However, you can allocate pointers to functions with the new operator. You cannot create a reference with the new operator.

When the object being created is an array, only the first dimension can be a general expression. All subsequent dimensions must be constant integral expressions. The first dimension can be a general expression even when an existing type is used. You can create an array with zero bounds with the new operator. For example:

char * c = new char[0];

In this case, a pointer to a unique object is returned.

An object created with operator new() or operator new[]() exists until the operator delete() or operator delete[]() is called to deallocate the object's memory. A delete operator or a destructor will not be implicitly called for an object created with a new that has not been explicitly deallocated before the end of the program.

If parentheses are used within a new type, parentheses should also surround the new type to prevent syntax errors.

Related Discussions
Thread Thread Starter Forum Replies Last Post
S60 3rd Edition, Feature Pack 2 felixksp General Symbian C++ 4 2007-09-14 17:38
creating dialog devloper Symbian User Interface 3 2007-04-28 08:52
how to create a message with file in inbox wzym General Symbian C++ 3 2003-11-25 14:50
Symabian Project anupamcins Symbian Tools & SDKs 2 2004-08-03 12:55
Restoring Backup to new 6230 ahsanejaz General Discussion 0 2004-11-30 09:27
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX