properties

Chris central_p at hotmail.com
Sat Feb 18 21:14:10 PST 2006


Thank you, Chris


I cannot say I understand D properties very well. I've  just compiled my
"Hi" program to test compiling and debugging:


main.d

import std.stdio;
import student;

void main()
{
     int i;
     i = 1;
     i++;
     printf("Hi! The number is: %d",i);

     Student student = new Student("John Smith", 30);
     writefln("\nFile is:  %s", __FILE__);
     writefln("Line is:  %s", __LINE__);

     // Debug variables needed to debug with WinDbg
     debug
     {
         char [] h_Name = student.Name;
         int h_Age = student.Age;
     }
     writefln("\nName is: %s\nAge is:  %d", student.Name, student.Age);

     printf("\n\nNow press a key to continue!");
     getch();
}


student.d

class Student
{
     private
     {
         char [] name;
         int   age;
     }

     char [] Name() { return name; }
     void Name(char [] value) { name = value; }
     int Age() { return age; }
     void Age(int value) { age = value; }


     Student next;

     this(char [] name, int age)
     {
         this.name = name;
         this.age = age;
     }
}





Chris Sauls wrote:
> Chris wrote:
>> John Stoneham wrote:
>>
>>> Chris wrote:
>>>
>>>> I have another question:
>>>>
>>>> Can Visual Studio 2005 be used to compile and debug D programs?
>>>
>>>
>>> The wiki has a few debuggers mentioned:
>>> http://www.prowiki.org/wiki4d/wiki.cgi?DebugEnvironments
>>>
>>> As far as I know, the VS2005 debugger can't be used, but I may be wrong.
>>
>>
>> Thank you for you tips! I finally got WinDbg working. OpenWatcom seems 
>> as if it is working too.
>>
>> BTW. How do you watch strings?
>>
>> I have this:
>>
>>     debug
>>     {
>>         char [] h_Name = student.Name;
>>         int h_Age = student.Age;
>>     }
>>
>> ..Name and .Age are properties. For .Age I get a number but I also get 
>> a scary number for the string .Name? Can't I view the string value 
>> somehow?
>>
>> And also this doesn't work for properties.
>>
>> debug
>> {
>>   int *h_ounces = &hamburger.ounces;
>>   float *h_cost = &hamburger.cost;
>> }
>>
>> Regards,
>>        Chris
> 
> Its not real pretty, but this should work if they're just fields:
> 
> # debug {
> #   int   * h_ounces ;
> #   float * h_cost   ;
> #
> #   with (hamburger) {
> #     h_ounces = &ounces ;
> #     h_cost   = &cost   ;
> #   }
> # }
> 
> If, on the other hand, the properties are gettor methods, then I don't 
> think you can 'address' them at all - except maybe with an 'address 
> gettor'.
> 
> # class Hamburger {
> #   // ... blah
> #   int* ouncesPtr () { return &p_ounces; }
> # }
> # // ... blah
> # with (hamburger)
> #   int * h_ounces = ouncesPtr ;
> 
> -- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list