What problems can you find in the following excerpt of a Symbian program? How and in what situations would they degenerate the program's execution? How should the program be corrected?
// Operations to be identified in the screen.
enum TMode \{EEat, ESleep, EWait\};
// Temporary resource for drawing.
class CMyResource
\{
public:
CMyResource (CScreenShot \& aParent);
ConstructL ();
-CMyResource ();
void ShowEatingItemL();
void ShowSleepingItemL ();
void ShowlaitingItemL();
private:
...
\};
// Draw the right symbol to myWindow.
void Behave(TMode aMode, CScreenShot\& myWindow)
\{
CMyResource *res $=0 ; / /$ Local drawing resource
// Local two-phase construction.
res = new CMyResource (myWindow);
res->ConstructL ();
CleanupStack: : PushL (res);
// Selecting symbol to draw.
switch (aMode)
\{
case EEat:
res->ShowEatingItemL ();
break;
case ESleep:
res->ShowSleepingItemL ();
break;
case EWait:
res->ShowWaitingItemL ();
break;
default:
User: : Leave (KNoSuchActivity) ;
break;
\} // switch
// Drawing complete, resource no longer needed.
CleanupStack: : PopAndDestroy(); // res
delete res;
// Fix figure to the screen.
MakeImagePermanentL (myWindow) ;
\}