Click here to Skip to main content
15,924,195 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: what is difference betwn pointer and referece Pin
melwyn6-Nov-03 23:07
melwyn6-Nov-03 23:07 
GeneralRe: what is difference betwn pointer and referece Pin
Rajesh match6-Nov-03 23:39
Rajesh match6-Nov-03 23:39 
GeneralRe: what is difference betwn pointer and referece Pin
melwyn6-Nov-03 23:52
melwyn6-Nov-03 23:52 
GeneralRe: what is difference betwn pointer and referece Pin
Rajesh match7-Nov-03 0:04
Rajesh match7-Nov-03 0:04 
GeneralRe: what is difference betwn pointer and referece Pin
melwyn7-Nov-03 0:49
melwyn7-Nov-03 0:49 
AnswerRe: what is difference betwn pointer and referece Pin
Joaquín M López Muñoz7-Nov-03 0:38
Joaquín M López Muñoz7-Nov-03 0:38 
GeneralRe: what is difference betwn pointer and referece Pin
souldog7-Nov-03 9:12
souldog7-Nov-03 9:12 
GeneralRe: what is difference betwn pointer and referece Pin
Joaquín M López Muñoz7-Nov-03 9:51
Joaquín M López Muñoz7-Nov-03 9:51 
It is a matter of the compiler catching errors or having them show up at runtime.

I don't think substituting references for pointers in function declarations catches any error at runtime. For instance, consider a program like this
void foo(int *i);
 
...
 
// invocations of f have one of these two forms
 
f(something);
f(&something);
If I change the definition of foo to allegedly make it more robust, the whole program has to be changed as
void foo(int& i);
 
...
 
f(*something);
f(something);
Any program compiling with the first definition of foo will compile just the same with the second definition (after modifying the invocations to foo.) So, you won't catch more errors at compile time.

References can help prevent problems at compile time, but not when used as function arguments --rather, when replacing pointer variables declarations with reference variables declarations, as in
// version 1
int * p;
 
// version 2
int& p=... // it is mandatory that p be initialized, which may help preserve
// the sanity of the program
Anyway replacing pointers with references is not always feasible, if the concept of null object is valid, or if the pointer must be rebound (references cannot.)

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralRe: what is difference betwn pointer and referece Pin
souldog7-Nov-03 10:43
souldog7-Nov-03 10:43 
QuestionWhat is make file ? Pin
Rajesh match6-Nov-03 18:35
Rajesh match6-Nov-03 18:35 
AnswerRe: What is make file ? Pin
parths6-Nov-03 22:44
parths6-Nov-03 22:44 
Generalknow how to attack parallel port in win2k Pin
vhunghl6-Nov-03 16:54
vhunghl6-Nov-03 16:54 
GeneralRe: know how to attack parallel port in win2k Pin
Per Nilsson6-Nov-03 20:11
Per Nilsson6-Nov-03 20:11 
GeneralRe: know how to attack parallel port in win2k Pin
vhunghl6-Nov-03 20:57
vhunghl6-Nov-03 20:57 
GeneralRe: know how to attack parallel port in win2k Pin
Per Nilsson6-Nov-03 20:59
Per Nilsson6-Nov-03 20:59 
GeneralSimple Image Capture method Pin
zecodela6-Nov-03 16:42
zecodela6-Nov-03 16:42 
Generalhelp! Pin
yunhe6-Nov-03 16:14
yunhe6-Nov-03 16:14 
GeneralRe: help! Pin
Christian Graus6-Nov-03 17:13
protectorChristian Graus6-Nov-03 17:13 
GeneralRe: help! Pin
Roger Allen7-Nov-03 5:05
Roger Allen7-Nov-03 5:05 
GeneralPrims Algorithm Pin
dupontracegirl6-Nov-03 13:18
dupontracegirl6-Nov-03 13:18 
GeneralRe: Prims Algorithm Pin
dupontracegirl6-Nov-03 13:19
dupontracegirl6-Nov-03 13:19 
GeneralRe: Prims Algorithm Pin
Joaquín M López Muñoz6-Nov-03 20:30
Joaquín M López Muñoz6-Nov-03 20:30 
QuestionHow do you call an exe programmatically? Pin
Steve Messer6-Nov-03 11:30
Steve Messer6-Nov-03 11:30 
AnswerRe: How do you call an exe programmatically? Pin
Navin6-Nov-03 12:48
Navin6-Nov-03 12:48 
GeneralRe: How do you call an exe programmatically? Pin
Steve Messer6-Nov-03 13:27
Steve Messer6-Nov-03 13:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.