summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rwxr-xr-xvala.html.markdown19
1 files changed, 19 insertions, 0 deletions
diff --git a/vala.html.markdown b/vala.html.markdown
index 036e873d..a65c528f 100755
--- a/vala.html.markdown
+++ b/vala.html.markdown
@@ -251,6 +251,25 @@ interface InterfaceDemo { // Can be used as a mixin
// ...
}
+// Since method overloading isn't possible, you can use named constructors
+// to get the same functionality.
+
+public class Calculator : GLib.Object {
+
+ public Calculator() {
+ }
+
+ public Calculator.with_name(string name) {
+ }
+
+ public Calculator.model(string model_id, string name = "") {
+ this.with_name(@"$model_id $name"); // Chained constructors with "this"
+ }
+ ~Calculator() { } // Only needed if you're using manual memory management
+}
+
+var calc1 = new Calculator.with_name("Temp");
+var calc2 = new Calculator.model("TI-84");
enum HouseSize {
SMALL,