cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
"->" and "."?
"->" and "."?
May 5, 2012 at 3:14pm UTC
even821
(177)
whats the difference between the two?
i know both are used to acces members of an object, but when do i use "->", and when do i use "."?
Last edited on
May 5, 2012 at 3:15pm UTC
May 5, 2012 at 3:23pm UTC
hanst99
(2869)
-> is a convenient shorthand for accessing members of a struct/class instance by a pointer
so you can write
1
2
MyObj* obj = <get-obj> obj->method();
Instead of
1
2
MyObj* obj = <get-obj> (*obj).method();
May 5, 2012 at 3:27pm UTC
even821
(177)
so -> is used when the pointer is pointing to an object, not to a variabel then?
May 5, 2012 at 3:30pm UTC
viliml
(791)
x->y is nothing more than a short way of saying (*x).y!
May 5, 2012 at 3:34pm UTC
even821
(177)
yes, i already understood that part from the first reply. i simply asked when to use it...but i have allready figured it out so thanks for answering :P
Topic archived. No new replies allowed.