What is the function of the '->' in that line?

  • Thread starter Thread starter NCEE
  • Start date Start date
  • Tags Tags
    Function Line
Click For Summary
SUMMARY

The '->' operator in C++ is used to access members of a class or structure through a pointer. In the example provided, "pTerm = pid->pGain * error;", 'pid' is a pointer to a class or structure, and 'pGain' is a member of that class or structure. The expression 'pid->pGain' is functionally equivalent to dereferencing the pointer with '(*pid).pGain', but the '->' operator offers a more concise and readable syntax.

PREREQUISITES
  • Understanding of C++ pointers and memory management
  • Familiarity with classes and structures in C++
  • Basic knowledge of operator overloading in C++
  • Experience with C++ syntax and conventions
NEXT STEPS
  • Study C++ pointer syntax and operations
  • Learn about class and structure member access in C++
  • Explore operator overloading in C++ for custom types
  • Review best practices for using pointers in C++ programming
USEFUL FOR

C++ developers, software engineers, and students learning object-oriented programming concepts.

NCEE
Messages
4
Reaction score
0
I was going through a bit of open source code when I came upon this line
"pTerm = pid->pGain * error;"

What is the function of the '->' in that line?
 
Engineering news on Phys.org
pid is a pointer to a class or structure.
pGain is a member of the class or structure.
pid -> pGain means the same as (*pid).pGain (but it looks prettier).
 

Similar threads

  • · Replies 14 ·
Replies
14
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
24
Views
3K
Replies
33
Views
4K
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 25 ·
Replies
25
Views
6K