C++ Bug: Object is destroyed twice

Cerrado Publicado Oct 1, 2003 Pagado a la entrega
Cerrado Pagado a la entrega

When running this code, I get a memory access violation, complaining that the memory area is being deleted twice:

#include "AbstractActivator.h"

// 3 classes involved:

// TextDisplayer: Base class for a hierarchy of functors that

// display a string in a certain way.

//

// Activator: Base class for a hierarchy.

//

// ActivatorFactory: Base class of a hierarchy of functors

// taht return a pointer to a std::list<Activator>

//

int main()

{

// If I don't create any intances of

// TextDisplayer, I don't get any errors

TextDisplayer show;

// ActivatorFactory is a functor that returns

// a pointer to an stl::list<Activator>

// Each Activator instance contains a pointer

// to a TextDisplayer instance. This internal instance

// is deleted in the Activator destructor.

ActivatorFactory fact;

// Activartors is a typedef for stl::list<Activator>

Activators * acts = fact();

Activators::iterator i;

// Call the activate method of all activators

for(i = acts->begin(); i != acts->end(); ++i)

{

(*i).activate();

}

// Delete the dynamically created list<Activators>

// This is were I get into trouble. This calls

// the destructor of Activator, that tries to delete

// the internal TextDisplayer. That line creates an

// error, complaining that that memory area has already

// been deleted.

delete acts;

return 1;

}

## Deliverables

1) Explanation of this error is occurring.

2) How to fix it.

3) Modified version of the my source code, with the bug fixed.

## Platform

Windows

Programación en C Ingeniería MySQL PHP Arquitectura de software Verificación de software

Nº del proyecto: #2983168

Sobre el proyecto

38 propuestas Proyecto remoto Activo Oct 15, 2003

38 freelancers están ofertando un promedio de $17 por este trabajo

jeden

See private message.

$8.5 USD en 2 días
(24 comentarios)
6.7
bilalahmed

See private message.

$38.25 USD en 2 días
(79 comentarios)
6.3
mikemozhaev

See private message.

$6.8 USD en 2 días
(21 comentarios)
5.0
esegura

See private message.

$6.8 USD en 2 días
(22 comentarios)
4.8
lioncodevw

See private message.

$6.8 USD en 2 días
(3 comentarios)
4.1
igali

See private message.

$17 USD en 2 días
(15 comentarios)
4.0
lalesculiviu

See private message.

$38.25 USD en 2 días
(18 comentarios)
4.2
teamvw

See private message.

$8.5 USD en 2 días
(36 comentarios)
3.8
seirus

See private message.

$33.15 USD en 2 días
(36 comentarios)
4.0
mixelvw

See private message.

$5.1 USD en 2 días
(32 comentarios)
3.7
lonapz

See private message.

$8.5 USD en 2 días
(10 comentarios)
2.8
Annu

See private message.

$8.5 USD en 2 días
(1 comentario)
2.4
homeworktutor

See private message.

$12.75 USD en 2 días
(12 comentarios)
2.4
gurux

See private message.

$19.55 USD en 2 días
(4 comentarios)
2.7
vw938212vw

See private message.

$21.25 USD en 2 días
(5 comentarios)
1.5
aromanvw

See private message.

$3.4 USD en 2 días
(3 comentarios)
1.3
manwevw

See private message.

$25.5 USD en 2 días
(1 comentario)
0.5
templatebeetle

See private message.

$34 USD en 2 días
(0 comentarios)
0.0
vw816832vw

See private message.

$29.75 USD en 2 días
(0 comentarios)
0.0
mbnvw

See private message.

$12.75 USD en 2 días
(0 comentarios)
0.0