From 68e5d98ebdf130820e54b9a0c0b386d0b43434b8 Mon Sep 17 00:00:00 2001 From: Avi KC <132746547+thisismars-x@users.noreply.github.com> Date: Thu, 10 Jul 2025 15:27:07 +0545 Subject: [PATCH] Update ch05-03-method-syntax.md In "Where's the '->' Operator?" Line 1: "In C and C++, two different operators are used for calling methods.....", implies C supports methods like C++ does, which is obviously untrue. --- src/ch05-03-method-syntax.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ch05-03-method-syntax.md b/src/ch05-03-method-syntax.md index ab92d19ac0..e35ae38844 100644 --- a/src/ch05-03-method-syntax.md +++ b/src/ch05-03-method-syntax.md @@ -89,19 +89,20 @@ are and how to designate a field or method as public or private in [Chapter 7][public]. > ### Where’s the `->` Operator? -> -> In C and C++, two different operators are used for calling methods: you use -> `.` if you’re calling a method on the object directly and `->` if you’re -> calling the method on a pointer to the object and need to dereference the -> pointer first. In other words, if `object` is a pointer, -> `object->something()` is similar to `(*object).something()`. -> -> Rust doesn’t have an equivalent to the `->` operator; instead, Rust has a -> feature called _automatic referencing and dereferencing_. Calling methods is -> one of the few places in Rust with this behavior. -> -> Here’s how it works: when you call a method with `object.something()`, Rust -> automatically adds in `&`, `&mut`, or `*` so `object` matches the signature of +> +> In C and C++, two different operators are used to access members: you use +> `.` when working with an object directly, and `->` when working with a +> pointer to the object and need to dereference it first. In C++, these +> operators can be used to call methods; in C, they are only used to access +> struct fields. In other words, if `object` is a pointer, +> `object->something()` is similar to `(*object).something()`. +> +> Rust doesn’t have an equivalent to the `->` operator; instead, Rust has a +> feature called _automatic referencing and dereferencing_. Calling methods is +> one of the few places in Rust with this behavior. +> +> Here’s how it works: when you call a method with `object.something()`, Rust +> automatically adds in `&`, `&mut`, or `*` so `object` matches the signature of > the method. In other words, the following are the same: > >