Solved

Another easy one...

Posted on 1998-10-06
4
201 Views
Last Modified: 2010-04-01
What does the "->" operator do?  I keep coming across it, but it isn't covered in any of the books I've ever read on C++.  Here's a sample line from the DirectX SDK:

g_pDD->Release();

Does this put the variable g_pDD through the Release() function?

Thanks,  

Raydot.
0
Comment
Question by:Raydot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 1174520
It accesses a class member function through a pointer to an instance of the class.

If you have e.g.
class C: public whatever
{
.
void DoSomething();
};

C c;
C* p = &c;

c.DoSomething();

is equivalent to

p->DoSomething();
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1174521
Damn! jkr types fast...

Guess I'll put this in as a comment since he beat me to submit button!

-> refers to the a member of a structure or class, when the structure/class is referenced by a pointer.

This is similar to the . operator used to refer to a member of struct/class.

-> is used when you have a pointer to a class/struct
 is used when you have a variable of the class/struct type

In your example g_pDD is a pointer to an object of some class

g_pDD->Release() calls the release member function of that object

0
 
LVL 1

Expert Comment

by:Staplehead
ID: 1174522
grf... guess i'm not the quickest draw in the east... (!)

raydot,

this operator was inherited (sorry for the pun) from C; originally, it accessed a member of a struct through a pointer:

myStruct *foo;

foo->bar = 3;

of course, as jkr mentioned, in C++ it also allows you to access a member (data or function) of an instance of an object through a pointer to that instance...

Larry
0
 
LVL 3

Author Comment

by:Raydot
ID: 1174523
Wow, you guys need to lay off the coffee!  That was the fastest I ever got an answer on anything, my whole life.  Thanks...

Raydot.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question