cppintf: with param

This commit is contained in:
xushiwei
2024-06-22 02:39:29 +08:00
parent bfa4e08a4e
commit 26b771f9f9
3 changed files with 13 additions and 13 deletions

View File

@@ -3,23 +3,23 @@ package main
import (
"github.com/goplus/llgo/_demo/cppintf/foo"
"github.com/goplus/llgo/c"
"github.com/goplus/llgo/c/math"
)
type Bar struct {
foo.Callback
a int
b float64
}
func NewBar(a int, b float64) *Bar {
func NewBar(a int) *Bar {
return &Bar{
Callback: foo.Callback{
Vptr: &foo.CallbackVtbl{
ValA: c.Func((*Bar).getA),
ValB: c.Func((*Bar).getB),
Val: c.Func((*Bar).getA),
Calc: c.Func((*Bar).sqrt),
},
},
a: a, b: b,
a: a,
}
}
@@ -27,11 +27,11 @@ func (p *Bar) getA() int {
return p.a
}
func (p *Bar) getB() float64 {
return p.b
func (p *Bar) sqrt(v float64) float64 {
return math.Sqrt(v)
}
func main() {
bar := NewBar(1, 2.0)
bar := NewBar(1)
foo.F(&bar.Callback)
}