Encerrado

C++ Bug: Object is destroyed twice

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

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

Ver mais: string stl, string iterator, string in c programming, string c programming, stl string, stl programming, stl list iterator, stl list, stl iterator, stl in c, stl code, stl c, stl 2, std list c, std list, pointer programming, object in programming, list stl, list iterator c, list in stl, iterator string, iterator stl, iterator it, iterator in c, iterator end

Acerca do Empregador:
( 0 comentários ) Spain

ID do Projeto: #2983168

41 freelancers estão ofertando em média $17 para este 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
lalesculiviu

See private message.

$38.25 USD in 2 dias
(18 Comentários)
4.2
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
seirus

See private message.

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

See private message.

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

See private message.

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

See private message.

$8.5 USD in 2 dias
(20 Comentários)
3.3
dmitrynaumov

See private message.

$3.4 USD in 2 dias
(9 Comentários)
2.9
lonapz

See private message.

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

See private message.

$19.55 USD in 2 dias
(4 Comentários)
2.7
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
roman73

See private message.

$25.5 USD in 2 dias
(2 Comentários)
2.3
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