My book (The complete Idiots Guide to C++) never used it or explained it.
eg: g_glRender->Init();
TIA
Printable View
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;
}
Cool Thanks Everyone
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;
" -> " is also knows as the, "member selection operator" FYI
useless trivia :cool:
Over there.Quote:
Originally Posted by jimboob