23.07.2012 Views

MATLAB C++ Math Library Reference

MATLAB C++ Math Library Reference

MATLAB C++ Math Library Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Assignment Operators<br />

mwArray &operator=(const mwArray&);<br />

The final operator, =, is the assignment operator. <strong>C++</strong> requires that the<br />

assignment operator be a member function. Like the copy constructor, the<br />

assignment operator does not actually make a copy of the input array, but<br />

rather references (keeps a pointer to) the input array’s data; this is an<br />

optimization made purely for efficiency, and has no effect on the semantics of<br />

assignment. If you write A = B andthenmodifyB, the values in A will remain<br />

unchanged.<br />

User-Defined Conversion<br />

There is only one user-defined conversion: from an mwArray to a<br />

double-precision floating-point number. This conversion function only works if<br />

the mwArray is scalar (1-by-1) and noncomplex.<br />

operator double() const;<br />

Memory Management<br />

Overloading the operators new and delete provides the necessary hooks for<br />

user-defined memory management. The <strong>MATLAB</strong> <strong>C++</strong> <strong>Math</strong> <strong>Library</strong> has its<br />

own memory management scheme.<br />

If this scheme is inappropriate for your application, you can modify it.<br />

However, you should not do so by overloading new and delete, becausethe<br />

mwArray class already contains overloaded versions of these operators.<br />

void *operator new(size_t size)<br />

void operator delete(void *ptr, size_t size)<br />

Array Size<br />

In <strong>MATLAB</strong>, the size() function returns the size of an array as an array. The<br />

<strong>MATLAB</strong> <strong>C++</strong> <strong>Math</strong> <strong>Library</strong> provides a corresponding version of size() that<br />

also returns an array. Because this <strong>C++</strong> version allocates an array to hold just<br />

two integers, it is not efficient. The mwArray Size member functions below<br />

return the size of an array more efficiently.<br />

12

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!