1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

generics: implement method generics (fix #7638) (#7732)

This commit is contained in:
yuyi
2021-01-01 01:00:22 +08:00
committed by GitHub
parent 2bc9ee4d88
commit c3dafad7ef
5 changed files with 86 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
struct Point {
mut:
x int
y int
}
fn (mut p Point) translate<T>(x T, y T) {
p.x += x
p.y += y
}
fn test_generic_method() {
mut pot := Point{}
pot.translate<int>(1, 3)
pot.translate(1, 3)
println(pot)
assert pot == Point{
x: 2
y: 6
}
}