Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Another easy one...

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

Industry Leaders: 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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.

670 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