Tuesday, April 10, 2012

How do you allocate memory at a predetermined location?

How do i allocate memory using new at a fixed location? My book says to do this:



char *buf=new char[sizeof(sample)];
sample *p=new(buf)sample(10,20);


Here new is allocating memory at buf's address, and (10,20) are values being passed. But what is sample? is it an address or a data type?





No comments:

Post a Comment