By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,305 Members | 1,628 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,305 IT Pros & Developers. It's quick & easy.

allocator.destroy()

P: n/a
Why does the value of the below int pointer not disappear after using
destroy:

std::allocator<intallo;

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.
Jun 4 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
desktop wrote:
Why does the value of the below int pointer not disappear after using
destroy:

std::allocator<intallo;

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.
Jun 4 '07 #2

P: n/a
On 4 Juni, 23:14, Gianni Mariani <gi3nos...@mariani.wswrote:
desktop wrote:
Why does the value of the below int pointer not disappear after using
destroy:
std::allocator<intallo;
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.
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.

--
Erik Wikström

Jun 5 '07 #3

P: n/a
Erik Wikström wrote:
On 4 Juni, 23:14, Gianni Mariani <gi3nos...@mariani.wswrote:
>desktop wrote:
>>Why does the value of the below int pointer not disappear after using
destroy:
std::allocator<intallo;
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.

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.
Jun 5 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.