简体   繁体   中英

Scope resolution and the this operator

In a (C++) class I took recently the teacher mentioned that using the -> operator was a tiny bit slower than using dot notation and dereferencing your pointer manually (eg (*ptr) ).

  1. Is this true, and, if so, why?
  2. Does this apply to C as well?

The -> operator is neither slower or faster than . operator. The fact is that dereferencing something is slower than just access to a memory location, because there is one more indirection. And this is a fact of life, either in C and C++ and any other language.

In C++, you have also references , so you can dereference something using the . too! So the problem here is not arrow-vs-dot , the problem is if the compiler can go straight to a value or if it must search for its address before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM