My book (The complete Idiots Guide to C++) never used it or explained it.
eg: g_glRender->Init();
TIA
My book (The complete Idiots Guide to C++) never used it or explained it.
eg: g_glRender->Init();
TIA
It's syntax sugar for (*g_glRender).Init(). You can also define an operator->().
-> is the pointer operator.
Kuphryn
its a pointer operator to a variable or function in a class
eg.
Code:class person { public: int number; }; int main() { person loser; person *ptrLoser; ptrLoser=&loser; ptrLoser->number=10; return 0; }
Woop?
You use it when dereferencing an object pointer:
the reason you can't just do:Code:#include <iostream> using namespace std; class person { public: int age; }; void grow (person* guy); int main(int argc, char *argv[]) { person ryan; /* makes my age 17 */ ryan.age = 17; cout<<"Ryan was, "<<ryan.age<<" years old."<<endl; /* sends the address of me off to grow */ grow(&ryan); cout<<"Ryan was, "<<ryan.age<<" years old."<<endl; return 0; } void grow(person* guy) { guy->age = 18; /* note that (*guy).age = 18; would work here. */ }
is because the period is evaluated before the *. So you'd have to use parentheses to alter the order of operations. Alas making you use the:Code:*guy.age = 18;
Although that is rather ugly, and not the easiest thing to work with, so c++ has the -> operator. which is the exact same thing.Code:(*guy).age = 18;
Code:(*guy).age = 18; == guy->age = 18;
Because I can't.
" -> " is also knows as the, "member selection operator" FYI
useless trivia
Last edited by The Brain; 07-18-2004 at 06:43 AM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
Over there.Originally Posted by jimboob
c++->visualc++->directx->opengl->c++;
(it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)