Prev: char *
Next: boolean
From: Eric Kaplan on
what are the difference between the following 4 variables?

const int * start
int* const start
int const& start
Request(int const& start);
From: Eric Kaplan on
more specific - for passing parameter, what's different between

& OR *

pointer vs reference ??

Request(string const& start, string const& end);
Request(string const* start, string const* end);
From: Eric Kaplan on
I suppose the following is exact same thing right?

int * const start
int const * start

both means the pointer is constant - (pointer always point to same
address)
From: Alf P. Steinbach on
* Eric Kaplan:
> what are the difference between the following 4 variables?
>
> const int * start
> int* const start
> int const& start
> Request(int const& start);

The last line does not declare a variable.

And the three lines above are syntactically invalid as declarations, so do not
declare variables either.

So instead of 4 variables, you have no variables.


Cheers, & hth.,

- Alf
From: Alf P. Steinbach on
* Eric Kaplan:
> more specific - for passing parameter, what's different between
>
> & OR *
>
> pointer vs reference ??
>
> Request(string const& start, string const& end);
> Request(string const* start, string const* end);

The first one essentially communicates (to programmers) that you're not
supporting null-pointers, and it lets you call the function with any arguments
that can be implicitly converted to string, such a literal strings.

The second communicates that you're supporting null-pointer arguments, does not
support implicit conversion to string, and yields more awkward notation.

With some argument type other than string, the second form might instead
communicate that the function expects pointers to dynamically allocated objects,
without taking ownership (for ownership use smart pointers).


Cheers, & hth.,

- Alf
 |  Next  |  Last
Pages: 1 2 3
Prev: char *
Next: boolean