|
-
September 13th, 2002, 04:02 AM
#1
How to pass the pointer back through function parameter
Hello,
I have a question about function parameter passing:
In my program, there is a pointer pointing to an image, say
CImage * pImage;
The program needs to call a function to do something.
void f( CImage * pImg );
What I want is that: if pImage is not null, function f(...) just uses it; if function f(...) finds pImg is null, it can load image and pass the pointer to image back to my program through a parameter. It seems that my above parameter passing can not do it.
Can anybody help me to solve the problem and how should I pass the parameters?
Thanks a lot!
-
September 13th, 2002, 04:06 AM
#2
Code:
void f(CImage*& pImage)
{
if (pImage == 0) // Don't use NULL
{
pImage = // whatever
}
// carry on
}
There will now begin a long debate on the merits of reference-to-pointer verus pointer-to-pointer.....
Correct is better than fast. Simple is better than complex. Clear is better than cute. Safe is better than insecure.
-- Sutter and Alexandrescu, C++ Coding Standards
Programs must be written for people to read, and only incidentally for machines to execute.
-- Harold Abelson and Gerald Jay Sussman
The cheapest, fastest and most reliable components of a computer system are those that aren't there.
-- Gordon Bell
-
September 13th, 2002, 04:44 AM
#3
Hi Graham
It is great and works perfect without changing my code.
Thanks!
-
September 13th, 2002, 06:14 AM
#4
Originally posted by neil0lee
Hi Graham
It is great and works perfect without changing my code.
Thanks!
Although I typically prefer the client syntax of pointer-to-pointer
argument passing, this statement speaks for itself 
--Paul
-
September 13th, 2002, 10:39 AM
#5
But that same statement is also the danger. The same usage will produce different results.
I still prefer **, but I really don't fee too strongly about either way. I do dislike the *& notation.
Jeff
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
|