Functions members of class need the reference of the class explicitly #2037
HudsonSchumaker
started this conversation in
Language design
Replies: 1 comment
-
I'm converting this to a discussion (it's not really an issue that can be fixed with a PR, it's a question, and overlaps with existing discussions). It may help though to search for other discussions on this topic, some of which discuss the issues and propose other syntax. https://github.com/carbon-language/carbon-lang/discussions?discussions_q=function+self |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For the given code
`class Point {
// Method defined inline
fn Distance[me: Self](x2: i32, y2: i32) -> f32 {
var dx: i32 = x2 - me.x;
var dy: i32 = y2 - me.y;
return Math.Sqrt(dx * dx + dy * dy);
}
// Mutating method declaration
fn Offset[addr me: Self*](dx: i32, dy: i32);
var x: i32;
var y: i32;
}
`
would be possible to do like in C++, that the compiler adds the reference to the instance and we are able to use the variable member directly ?
regards
Beta Was this translation helpful? Give feedback.
All reactions