Hi
would:
virtual void appendWaypoint(const Waypoint& wpt);
be different to:
virtual void appendWaypoint(const Waypoint &wpt);
or to?
virtual void appendWaypoint(const &Waypoint wpt);
Well I don't understand any.
Thanks
Hi
would:
virtual void appendWaypoint(const Waypoint& wpt);
be different to:
virtual void appendWaypoint(const Waypoint &wpt);
or to?
virtual void appendWaypoint(const &Waypoint wpt);
Well I don't understand any.
Thanks
The first two are the same. The third won't compile. Also, these aren't pointers; the & syntax is for references.
What you really should write is virtual void appendWaypoint(Waypoint const& wpt); because then you will not run into problems with certain template and lambda syntaxes. You would read that parameter declaration aloud as "the Waypoint const reference wpt", same as if it were spelled const Waypoint &wpt except all the words are in the same order.
The confusion over the '&' token indicating a pointer is because it is overloaded as the unary address-of operator, used to get the address of a variable (generate a pointer to the variable). A pointer is declared using the '*' token, which is overloaded as the dereferenced-value-of operator, used to get the value addressed by a pointer. In summary:
int an_int = 7; // an_int is of type int containing the value 7.
int& reference_to_int = an_int; // reference_to_int is an alias for an_int.
int* pointer_to_int = &reference_to_int; // the dereferenced value of pointer_to_int is of type int,
// and pointer_to_int is a pointer initialized to the address of an_int.
int another_int = *pointer_to_int; // another_int will now have the value 7.
Here's an explanation from Bjarne Stroustrup himself (about pointers, not references, but it also boils down to whitespace, just like it does for the first two cases you're asking about): http://www.stroustrup.com/bs_faq2.html#whitespace
Still a little confused. Are those the same?
typedef vector<Waypoint*> StdWaypointList;
typedef vector<*Waypoint> StdWaypointList;
Thanks
typedef vector<Waypoint*> StdWaypointList;
typedef vector<Waypoint> *StdWaypointList;
would that be the same? Thanks
No, they are fundamentally different. One is a pointer to a vector of Waypoints, the other is a vector of pointers to Waypoints.