Re: pesky Pointers !!
From: Rich (Someone_at_somewhere.com)
Date: 12/21/04
- Next message: Paul F. Johnson: "Re: Meaning of this declaration?"
- Previous message: Paul F. Johnson: "Re: Critical section ?"
- In reply to: Mike Wahler: "Re: pesky Pointers !!"
- Next in thread: Jonathan Mcdougall: "Re: pesky Pointers !!"
- Reply: Jonathan Mcdougall: "Re: pesky Pointers !!"
- Reply: Edd: "Re: pesky Pointers !!"
- Reply: Karl Heinz Buchegger: "Re: pesky Pointers !!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 20 Dec 2004 23:51:03 +0000 (UTC)
> '*pTest' is type 'string'
> Your function needs an argument of type 'string*' ('pointer to string').
> 'pTest' is type 'string*', and contains the address of 'sTest'.
>
> Write:
>
> StringTest(pTest);
>
Hi Thanks that worked, but I still dont understand why it worked, sorry :(
pTest looks just like a normal variable, which I thought was what a a
reference was used for ???
A reference as a parameter in a definition allows the programmer to pass
a reference without really knowing, i.e. no need to do &x or *x just x
and the function takes it as a reference instead of a copy.
From what I have kearnt about pointers and syntax using pointers it is
fairly straightforward you read from right to left e.g
int* px // px is a pointer to an int
*px dereferences the pointer to get the value
&px gives the address that *px points to
hopefully I have the above right?
So then if a function expects a parameter string* s
This is saying I need a pointer to a string passed to me??
So I thought I needed to pass the pointer as an argument thus requiring
either the use of the * or & before the pointer to show that it is a
pointer I am passing.
by passing pTest just like that it looks like a normal variable name ??
e.g if I just called the pointer Test then it would be confusing.
Now I am completely confused again doh!!
BTW
I notice a couple of different C++ styles one which out tutor insists we
use but I dislike
she insists on this type of style for parenthesis
a [ 10 ] // array
func ( 10, 20 ) // function call
I have also seen
a[10]
func(10,20)
I prefer an in between like
a[ 10 ]
func( 10 ,20 )
I use this because having the parenthesis next to the variable or
function name makes it look like it is part of it rather having the
variable part then a space then parenthesis looks kind of odd to me, I
can understand the spaces after first parenthesis and before last
parenthesis but why do some people insist on having a space before the
first parenthesis as well???
I know style is a matter of preference, but sometimes I think too many
spaces makes it more difficukt to read than no spaces.
I try to voice this with our tutor but she insists on the all spaces
style, this style I know is popular with Java programmers, but when did
it become a style in C++??
TIA
- Next message: Paul F. Johnson: "Re: Meaning of this declaration?"
- Previous message: Paul F. Johnson: "Re: Critical section ?"
- In reply to: Mike Wahler: "Re: pesky Pointers !!"
- Next in thread: Jonathan Mcdougall: "Re: pesky Pointers !!"
- Reply: Jonathan Mcdougall: "Re: pesky Pointers !!"
- Reply: Edd: "Re: pesky Pointers !!"
- Reply: Karl Heinz Buchegger: "Re: pesky Pointers !!"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|