I actually came across an example of this problem recently where I was forced to use a pointer.
I had a program that created random 3-D mountains. One of the control-variables was the "apex" or "peak" of the mountain.
there were 3 possible peaks:
1. right in the center (automatically generated)
2. off-center( randomly, and automatically generated)
or
3. user-defined
In main the peak had to declared before being created like this:
Depending on the command-line arguments, the peak was created in one of these three ways:
Code:
// Centered -automatic:
init_peak = new Coord( AUTO_X, AUTO_Y, AUTO_Z ); // Predefined x,y,z values
// Off-centered -automatic & random:
double init_x = get_rand_double( 0, 100 );
double init_y = get_rand_double( 0, 100 );
double init_h = get_rand_double( 50, 150 );
init_peak = new Coord( init_x, init_y, init_h );
// User-defined:
init_peak = new Coord( get_init_peak() ); // Func returns peak value entered by user