Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Another easy one...

Posted on 1998-10-06
4
Medium Priority
?
205 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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

926 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