Solved

Another easy one...

Posted on 1998-10-06
4
192 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
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now