new vs. malloc
View Single Post
> Compared to malloc(), why would one say that the 'new' operator is type-safe
> in a book? Thanks!
"Type-safe" loosely means that if you use the wrong type, the compiler
can tell you about it. Look at the following examples:
int* ip1 = static_cast<int*>(malloc(10 * sizeof(char)));
int* ip2 = static_cast<int*>(new char);
The second line will fail to compile, whereas the first one is just fine
(at least according to the compiler).
Reverse domain name to reply.