allocator.destroy()

D

desktop

Why does the value of the below int pointer not disappear after using
destroy:

std::allocator<int> allo;

int* ip;
allo.construct(ip,777);
std::cout << "*ip = " << *ip << std::endl;

allo.destroy(ip);


std::cout << "*ip = " << *ip << std::endl;

I get two prints with 777.
 
G

Gianni Mariani

desktop said:
Why does the value of the below int pointer not disappear after using
destroy:

std::allocator<int> allo;

int* ip;
allo.construct(ip,777);
std::cout << "*ip = " << *ip << std::endl;

allo.destroy(ip);


std::cout << "*ip = " << *ip << std::endl;

I get two prints with 777.

What do you think "destroy" does ? What do you expect it to do ?

It's undefined in this case. It might print 777 on your platform, it
might not on mine and it might melt the cpu on other platforms.
 
?

=?iso-8859-1?q?Erik_Wikstr=F6m?=

What do you think "destroy" does ? What do you expect it to do ?

It's undefined in this case. It might print 777 on your platform, it
might not on mine and it might melt the cpu on other platforms.

Did I read you post wrong? Because to me it seems like the call to
destroy is quite defined while the last line (where the pointer is
dereferenced) is undefined.
 
G

Gianni Mariani

Erik said:
Did I read you post wrong?

The second sentence refers to the code in the post - in particular the
second *ip.
... Because to me it seems like the call to
destroy is quite defined while the last line (where the pointer is
dereferenced) is undefined.

Yeah - it may be stated in an ambiguous way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,510
Members
48,195
Latest member
Tomjerry

Latest Threads

Top