Atmel CAVR-4 ユーザーズマニュアル
![Atmel](https://files.manualsbrain.com/attachments/0369829915bda09f9c2e00fb805a7753579683b5/common/fit/150/50/8d2bf08978ec3e5bc63f4343ac5e91ce8d0e40045619fa520d910d64af8f/brand_logo.png)
CAVR-4
Part 1. Using the compiler
Using C++
115
Use this syntax if you want to override both global and class-specific
operator
new
and
operator
delete
for any data memory.
Note that there is a special syntax to name the
operator
new
functions for each
memory, while the naming for the
operator
delete
functions relies on normal
overloading.
New and delete expressions
A
new
expression calls the
operator
new
function for the memory of the type given. If
a
class
,
struct
, or
union
type with a class memory is used, the class memory will
determine the
operator
new
function called. For example,
//Calls operator new _ _near(_ _near_size_t)
int _ _tiny *p = new _ _tiny int;
//Calls operator new _ _near(_ _near_size_t)
int _ _near *q = new int _ _near;
//Calls operator new[] _ _data16(_ _data16_size_t)
int _ _near *r = new _ _near int[10];
//Calls operator new _ _tiny(_ _tiny_size_t)
class _ _tiny S{...};
S *s = new S;
A
delete
expression calls the
operator
delete
function that corresponds to the
argument given. For example,
delete p; //Calls operator delete(void _ _near *)
delete s; //Calls operator delete(void _ _tiny *)
Note that the pointer used in a
delete
expression must have the correct type, that is, the
same type as that returned by the
new
expression. If you use a pointer to the wrong
memory, the result might be a corrupt heap. For example,
int _ _near * t = new _ _tiny int;
delete t; //Error: Causes a corrupt heap
TEMPLATES
Extended EC++ supports templates according to the C++ standard, except for the
support of the
support of the
export
keyword. The implementation uses a two-phase lookup which
means that the keyword
typename
has to be inserted wherever needed. Furthermore, at
each use of a template, the definitions of all possible templates must be visible. This
means that the definitions of all templates have to be in include files or in the actual
source file.
means that the definitions of all templates have to be in include files or in the actual
source file.