3 # This file illustrates the low-level C++ interface
4 # created by SWIG. In this case, all of our C++ classes
5 # get converted into function calls.
9 # ----- Object creation -----
11 print "Creating some objects:\n";
12 $c = examplec
::new_Circle
(10);
13 print " Created circle $c\n";
14 $s = examplec
::new_Square
(10);
15 print " Created square $s\n";
17 # ----- Access a static member -----
19 print "\nA total of $examplec::Shape_nshapes shapes were created\n";
21 # ----- Member data access -----
23 # Set the location of the object.
24 # Note: methods in the base class Shape are used since
25 # x and y are defined there.
27 examplec
::Shape_x_set
($c, 20);
28 examplec
::Shape_y_set
($c, 30);
29 examplec
::Shape_x_set
($s,-10);
30 examplec
::Shape_y_set
($s,5);
32 print "\nHere is their current position:\n";
33 print " Circle = (",examplec
::Shape_x_get
($c),",", examplec
::Shape_y_get
($c),")\n";
34 print " Square = (",examplec
::Shape_x_get
($s),",", examplec
::Shape_y_get
($s),")\n";
36 # ----- Call some methods -----
38 print "\nHere are some properties of the shapes:\n";
41 print " area = ", examplec
::Shape_area
($o), "\n";
42 print " perimeter = ", examplec
::Shape_perimeter
($o), "\n";
44 # Notice how the Shape_area() and Shape_perimeter() functions really
45 # invoke the appropriate virtual method on each object.
47 # ----- Delete everything -----
49 print "\nGuess I'll clean up now\n";
51 # Note: this invokes the virtual destructor
52 examplec
::delete_Shape
($c);
53 examplec
::delete_Shape
($s);
55 print $examplec::Shape_nshapes
," shapes remain\n";