C++ Bug: Object is destroyed twice

終了済み 投稿 Oct 1, 2003 着払い
終了済み 着払い

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

C プログラミング エンジニアリング MySQL PHP ソフトウェアアーキテクチャ ソフトウェアテスト

プロジェクトID: #2983168

プロジェクトについて

38個の提案 リモートプロジェクト アクティブ Oct 15, 2003

38人のフリーランサーが、平均$17 で、この仕事に入札しています。

jeden

See private message.

$8.5 USD 2日以内
(24件のレビュー)
6.7
bilalahmed

See private message.

$38.25 USD 2日以内
(79件のレビュー)
6.3
mikemozhaev

See private message.

$6.8 USD 2日以内
(21件のレビュー)
5.0
esegura

See private message.

$6.8 USD 2日以内
(22件のレビュー)
4.8
lioncodevw

See private message.

$6.8 USD 2日以内
(3件のレビュー)
4.1
igali

See private message.

$17 USD 2日以内
(15件のレビュー)
4.0
lalesculiviu

See private message.

$38.25 USD 2日以内
(18件のレビュー)
4.2
teamvw

See private message.

$8.5 USD 2日以内
(36件のレビュー)
3.8
seirus

See private message.

$33.15 USD 2日以内
(36件のレビュー)
4.0
mixelvw

See private message.

$5.1 USD 2日以内
(32件のレビュー)
3.7
lonapz

See private message.

$8.5 USD 2日以内
(10件のレビュー)
2.8
Annu

See private message.

$8.5 USD 2日以内
(レビュー1件)
2.4
homeworktutor

See private message.

$12.75 USD 2日以内
(12件のレビュー)
2.4
gurux

See private message.

$19.55 USD 2日以内
(4件のレビュー)
2.7
vw938212vw

See private message.

$21.25 USD 2日以内
(5件のレビュー)
1.5
aromanvw

See private message.

$3.4 USD 2日以内
(3件のレビュー)
1.3
manwevw

See private message.

$25.5 USD 2日以内
(レビュー1件)
0.5
templatebeetle

See private message.

$34 USD 2日以内
(0件のレビュー)
0.0
vw816832vw

See private message.

$29.75 USD 2日以内
(0件のレビュー)
0.0
mbnvw

See private message.

$12.75 USD 2日以内
(0件のレビュー)
0.0