I don't know the full answer but noticed one thing that causes confusion.

Change your code to:

case menuEvent:
{ // Add this open brace
  test a;
  handled = true;
  break;
} // add this close brace

Local variables defined inside a case statement I believe have scope to the
end of the switch statement if they are not inside curly braces.  It is
possible that if your code goes to a case statement below menuEvent()
then the constructor might never get called but the destructor will!
(I am not sure about that part)
I do remember reading that if you are declaring variables in your
case statements, you had better put { } around the case statement
like above to avoid any problems like this.

Brandon

Anne Srinivas wrote:
> 
> I have a class named test wihich looks like this:
> 
> class test
> {
> public:
> //Constructor for class test
>  test()
>  {
>             FrmAlert(CONSTRUCTOR);   // Displays message constructing
>  };
> 
> //Destructor for class test
>   ~test()
>  {
>           FrmAlert(DESTRUCTOR);  // Displays message de-constructing
> 
>  };
> };
> 
> I am creating an instance of my class test in menu event of
> MainFormHandleEvent like this:
> case menuEvent:
>    test a;
>    handled = true;
>    break;
> 
> But the alert DESTRUCTOR is being displayed even if i donot  do any
> thing with menu.
> Why should a destructor be called even before my class in instantiated?
> Even if we suppose that class is being instantiated, why should
> destructor be called first?
> It should be constructor which is called first!!
> 
> I am using Codewarrior rel 6 with palm os 3.1
> Where is the problem ?
> 
> Thanks in advance
> 
> --
> Anne Srinivas
> Software Engineer
> InfoTech Enterprises Ltd.
> Plot No 11,Infocity,
> Software Units Layout,
> Madhapur,Hyderabad 33
> 
> E-Mail :
> [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> 
> Tel (Office) : 3100855
> Tel (Resi)   : 3033761
> 
> --
> For information on using the Palm Developer Forums, or to unsubscribe, please see 
>http://www.palmos.com/dev/tech/support/forums/

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to