C++ Bug: Object is destroyed twice

Encerrado Postado Oct 1, 2003 Pago na entrega
Encerrado Pago na 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

Programação C Engenharia MySQL PHP Arquitetura de software Teste de Software

ID do Projeto: #2983168

Sobre o projeto

38 propostas Projeto remoto Ativo em Oct 15, 2003

38 freelancers estão ofertando em média $17 nesse trabalho

jeden

See private message.

$8.5 USD in 2 dias
(24 Comentários)
6.7
bilalahmed

See private message.

$38.25 USD in 2 dias
(79 Comentários)
6.3
mikemozhaev

See private message.

$6.8 USD in 2 dias
(21 Comentários)
5.0
esegura

See private message.

$6.8 USD in 2 dias
(22 Comentários)
4.8
lioncodevw

See private message.

$6.8 USD in 2 dias
(3 Comentários)
4.1
igali

See private message.

$17 USD in 2 dias
(15 Comentários)
4.0
lalesculiviu

See private message.

$38.25 USD in 2 dias
(18 Comentários)
4.2
teamvw

See private message.

$8.5 USD in 2 dias
(36 Comentários)
3.8
seirus

See private message.

$33.15 USD in 2 dias
(36 Comentários)
4.0
mixelvw

See private message.

$5.1 USD in 2 dias
(32 Comentários)
3.7
lonapz

See private message.

$8.5 USD in 2 dias
(10 Comentários)
2.8
Annu

See private message.

$8.5 USD in 2 dias
(1 Comentário)
2.4
homeworktutor

See private message.

$12.75 USD in 2 dias
(12 Comentários)
2.4
gurux

See private message.

$19.55 USD in 2 dias
(4 Comentários)
2.7
vw938212vw

See private message.

$21.25 USD in 2 dias
(5 Comentários)
1.5
aromanvw

See private message.

$3.4 USD in 2 dias
(3 Comentários)
1.3
manwevw

See private message.

$25.5 USD in 2 dias
(1 Comentário)
0.5
templatebeetle

See private message.

$34 USD in 2 dias
(0 Comentários)
0.0
vw816832vw

See private message.

$29.75 USD in 2 dias
(0 Comentários)
0.0
mbnvw

See private message.

$12.75 USD in 2 dias
(0 Comentários)
0.0