From 736613e26c911645237594980f6fa3064f634701 Mon Sep 17 00:00:00 2001 From: Michael Schaller Date: Wed, 5 Aug 2015 10:01:15 +0200 Subject: [Go] Documentation cleanup of obsolete 'callback' and 'extend' examples. After commit 17b1c1c (pull request 447; issue 418) the 'callback' and 'extend' examples have been removed in favor of the 'director' example. --- Examples/go/callback/index.html | 81 ----------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 Examples/go/callback/index.html (limited to 'Examples/go/callback/index.html') diff --git a/Examples/go/callback/index.html b/Examples/go/callback/index.html deleted file mode 100644 index b053cf547..000000000 --- a/Examples/go/callback/index.html +++ /dev/null @@ -1,81 +0,0 @@ - - -SWIG:Examples:go:callback - - - - - -SWIG/Examples/go/callback/ -
- -

Implementing C++ callbacks in Go

- -

-This example illustrates how to use directors to implement C++ -callbacks in Go. -

- -

-Because Go and C++ use inheritance differently, you must call a -different function to create a class which uses callbacks. Instead of -calling the usual constructor function whose name is New -followed by the capitalized name of the class, you call a function -named NewDirector followed by the capitalized name of the -class. -

- -

-The first argument to the NewDirector function is an instance -of a type. The NewDirector function will return an interface -value as usual. However, when calling any method on the returned -value, the program will first check whether the value passed -to NewDirector implements that method. If it does, the -method will be called in Go. This is true whether the method is -called from Go code or C++ code. -

- -

-Note that the Go code will be called with just the Go value, not the -C++ value. If the Go code needs to call a C++ method on itself, you -need to get a copy of the C++ object. This is typically done as -follows: - -

-
-type Child struct { abi Parent }
-func (p *Child) ChildMethod() {
-	p.abi.ParentMethod()
-}
-func f() {
-	p := &Child{nil}
-	d := NewDirectorParent(p)
-	p.abi = d
-	...
-}
-
-
- -In other words, we first create the Go value. We pass that to -the NewDirector function to create the C++ value; this C++ -value will be created with an association to the Go value. We then -store the C++ value in the Go value, giving us the reverse -association. That permits us to call parent methods from the child. - -

- -

-To delete a director object, use the function DeleteDirector -followed by the capitalized name of the class. -

- -

-

- -
- - -- cgit v1.2.3