Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of StructExample/D1

Show
Ignore:
Author:
Andrej08 (IP: 93.137.24.64)
Timestamp:
09/04/10 23:22:49 (14 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • StructExample/D1

    v0 v1  
     1= Struct = 
     2 
     3''Part of'' TutorialFundamentals 
     4 
     5== Description == 
     6 
     7Structs allow you to bind together basic data types into a more complicated paradigm. 
     8 
     9== Example == 
     10 
     11{{{ 
     12#!d 
     13struct Vehicle 
     14 
     15    double cost; 
     16    int wheels; 
     17} 
     18 
     19struct Utensil 
     20{  
     21    bool pointy; 
     22    bool tined;   
     23} 
     24 
     25void main() 
     26{       
     27    Vehicle car; 
     28    car.cost = 20_000; 
     29    car.wheels = 4; 
     30     
     31    Vehicle motorcycle; 
     32    motorcycle.cost = 2_000; 
     33    motorcycle.wheels = 2; 
     34     
     35    Vehicle boat; 
     36    boat.cost = 5_000;  
     37    boat.wheels = 0; 
     38 
     39 
     40    Utensil spoon; 
     41    spoon.pointy = false; 
     42    spoon.tined = false; 
     43     
     44    Utensil fork; 
     45    fork.pointy = true; 
     46    fork.tined = true; 
     47     
     48    Utensil knife; 
     49    knife.pointy = true; 
     50    knife.tined = false; 
     51} 
     52}}} 
     53 
     54== Source == 
     55 
     56Based on [http://jcc_7.tripod.com/d/tutor/simple/struct.html struct.html] by jcc7.