Sign in to follow this  
FGFS

pointers

Recommended Posts

FGFS    345

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

 

Share this post


Link to post
Share on other sites
ByteTroll    3035
Si is right. The first two are the same thing. They are a matter of personal programming style. The second one should not compile. Thirdly, these technically are not pointers, they are references. Pointers are declared with the "*" symbol and work a little differently than references.

Share this post


Link to post
Share on other sites
Bregma    9202

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.
Edited by Bregma

Share this post


Link to post
Share on other sites
FGFS    345

Still a little confused. Are those the same?

 

typedef vector<Waypoint*> StdWaypointList;

 

typedef vector<*Waypoint> StdWaypointList;

 

Thanks

Share this post


Link to post
Share on other sites
FGFS    345

typedef vector<Waypoint*> StdWaypointList;

 

typedef vector<Waypoint> *StdWaypointList;

 

would that be the same? Thanks

Share this post


Link to post
Share on other sites
FGFS    345

typedef vector<Waypoint*> StdWaypointList;

typedef vector<*Waypoint> StdWaypointList;

 

but those would be the same? Thanks

Edited by rip-off
Unredacting post

Share this post


Link to post
Share on other sites
FGFS    345

I do:

    StdWaypointList list;
SDatabase::getIls(name, list);

 

and get:

 error: no matching function for call to ‘SDatabase::getIls(const string&, StdWaypointList&)’

candidate is:
h:75:18: note: virtual void SDattabase::getIls(const string&, StdWaypointList*)

 

How to call getIls?

Thanks

Edited by rip-off
Unredacting post

Share this post


Link to post
Share on other sites
rip-off    10976

@OP: Do not redact posts.

@Everyone else, it is likely the OP has figured out the answer to the last question, as they tried to delete it.

Edited by rip-off

Share this post


Link to post
Share on other sites
FGFS    345

you definitely need another hobby than downrating my deleted crap. Why don't you get some vacation?

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this