On Feb 22, 10:48 am, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Quote:
cppquest wrote:
>
Quote:
I am doing something terrible wrong, but I dont understand why!
Maybe I am sitting too long in front of this box!
This is a breakdown of some code:
>
>
void assign_10_to(int a)
{
a = 10;
}
>
#include <iostream>
>
int main()
{
int b = 42;
assign_10_to(b);
std::cout << b;
}
>
What's this program going to print? Why? Now, let's change it
a little bit
>
int global_ten = 10;
>
void assign_10_to(int* a)
{
a = &global_ten;
}
>
#include <iostream>
>
int main()
{
int b = 42;
assign_10_to(&b);
std::cout << b;
}
>
What's this program oging to print? Why? What do you need to
change to make it print '10'?
>
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
To make it short and sweet,
- instead of passing "search" (an uninitialized pointer value with no
storage), pass "&search" (a pointer to the place you expect to find a
pointer on return from findMyDouble)
- modify findMyDouble to expect a pointer to a pointer
- in FindMyDouble, *localSearch = (address of found thing);
Or, as was suggested above, have findMyDouble return the address of
the found double. Then you have "search = findMyDouble()" - much
nicer.
Dana