Struct life time
    Qian Xu 
    quian.xu at stud.tu-ilmenau.de
       
    Sun Dec 14 11:47:10 PST 2008
    
    
  
Hi All,
I am new to D community. I have some problems with TimeOfDay struct.
I have defined a class:
========================================================
   class Test
   {
     TimeOfDay* getTime() {
       return a_valid_timeofday_pointer;
     }
     void setTime(TimeOfDay* value) {
       setValueAsTime(*value);
     }
     void setValueAsTime(TimeOfDay value) {
       Cout(TimeToChar(value)).newline;
     }
     /* the rest implementation of this class ... */
   }
========================================================
I try to test if setTime() works properly.
If I call
   Cout(TimeToChar(*TestObj.getTime())).newline;
It works. The console will show "10:00:00" for example.
If I call
   TestObj.setTime(TestObj.getTime());
It does not work. The console will show "33140305:48698544:485947594" 
for example.
If I change the setTime() function to
   void setTime(TimeOfDay* value) {
     Cout(TimeToChar(*value)).newline;
   }
or
   void setTime(TimeOfDay* value) {
     TimeOfDay copy = *value;
     setValueAsTime(copy);
   }
It works.
What's wrong with my code? (BTW: I do not want to change TimeOfDay* to 
TimeOfDay, otherwise null cannot be passed in.)
Thanks in advance.
-- 
Xu, Qian (stanleyxu)
  http://stanleyxu2005.blogspot.com
    
    
More information about the Digitalmars-d-learn
mailing list