|
-
Jun 28th, 2001, 12:17 PM
#1
Thread Starter
PowerPoster
what is difference between . and ->
I saw some code here and somebody decaled a type like:
POINT pt;
Now here accessed the "x" value in the variable pt like this:
switch(pt -> x)
Can I write the samething as:
switch(pt.x)
Is there any difference when you use "->" and "." ?
-
Jun 28th, 2001, 12:32 PM
#2
Monday Morning Lunatic
There's a big difference. See the other threads about -> because I don't want to type it out again
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 28th, 2001, 12:43 PM
#3
Re: what is difference between . and ->
Originally posted by abdul
I saw some code here and somebody decaled a type like:
POINT pt;
Now here accessed the "x" value in the variable pt like this:
switch(pt -> x)
Can I write the samething as:
switch(pt.x)
Is there any difference when you use "->" and "." ?
when you have a pointer, you use -> to access it's members, if it's just a regular variable you use .
Code:
struct test{
int x;
};
test tVar;
test* tpVar;
tVar.x = 5; //yes
tpVar.x = 5; //no
tpVar->x = 5; //yes
(*tpVar).x = 5 // yes
-
Jun 28th, 2001, 02:51 PM
#4
Thread Starter
PowerPoster
Can you expalain more
I have read about pointers but just forgot a bit so
Can you explain the examples which you gave me (a kind of another approach) because i did not understand the "struct" and then a bracket and then "You have declared a variable"
Can you explaim me please that what is happening in that example
That would be really helpfull
-
Jun 28th, 2001, 03:05 PM
#5
Frenzied Member
In fact, an expression involving the member-selection operator (->) is a shorthand version of an expression using the period (.) if the expression before the period consists of the indirection operator (*) applied to a pointer value. Therefore,
expression -> identifier
is equivalent to
(*expression) . identifier
when expression is a pointer value.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|