destructor called multiple times

Alexandre Oliva oliva@dcc.unicamp.br
Mon Sep 28 17:39:00 GMT 1998


Stephen Kennedy <steve@maths.tcd.ie> writes:

> The destructor for the compare function is called THREE times!
> (But the constructor only once)

> compare::compare()
> 0       bool compare::operator ()(int) const
> 1       bool compare::operator ()(int) const
> 4       bool compare::operator ()(int) const
> 9       bool compare::operator ()(int) const
> 16      bool compare::operator ()(int) const
> compare::~compare()
> compare::~compare()
> compare::~compare()

Ever heard of copy constructors? :-)

This additional declaration should make the problem clear:

        compare(const compare&) { cout << __PRETTY_FUNCTION__ << endl; } 

Thanks for your bug report.

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil




More information about the Gcc-bugs mailing list