Solved

Another easy one...

Posted on 1998-10-06
4
202 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

624 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