I know that this might sound like a stupid question, but why do I get an error which says something like “
cannot convert Object* to Object
” when I try to instantiate a new Object by using the statement “
Object obj = new Object();
“?
Am I to understand that the “new” keyword is reserved for pointers? Or is it something else?
newalways return pointer to object.if you write just
Object objit means thatobjwill hold the object itself. If it is declared this way inside function then memory will be allocated on stack and will be wiped once you leave that function.newallocates memory on heap, so the pointer can be returned from function. Note that pointer can also point to local (stack) variable also.