What's the difference between taking a dot (.) and doing ->?

Asked 2 years ago, Updated 2 years ago, 121 views

What is the difference between pointing a dot on an object (.) and doing -> in C++? I hate pointers.

c++ operator pointer

2022-09-21 14:16

1 Answers

1 .The operator cannot be written in the pointer. 2 foo->bar() = (*foo).bar()

2 must be enclosed in parentheses, such as (*foo). Since the . operator has a higher priority than the * operator, *foo.bar() is likely to cause compilation errors.

In addition, the . operator cannot be overloaded -> can be overloaded, so be careful when writing


2022-09-21 14:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.