Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 33,250 of 33,346    |
|    Martin Bonner to Robert Simpson    |
|    Re: Dereferencing pointer as argument to    |
|    30 Oct 13 09:29:55    |
      From: martinfrompi@yahoo.co.uk              On Wednesday, October 30, 2013 12:00:02 AM UTC, Robert Simpson wrote:       > My question is, if I have a function taking an argument by reference,       > is it bad practice to call that function with a dereferenced pointer?              No, provided you know (possibly because you have already checked) that       the pointer is not null.                     > void myfunc( Widget& w );       > std::unique_ptr< Widget > mywidget;               mywidget = new Widget; // Need to set mywidget.              > myfunc( *mywidget.get() );              > I have written this in my code, but I believe that       > there is probably a better solution.              "Better" in what sense?              If your pointer *can* be null, then you can't dereference       it to pass it to the function. You need a genuine object       to bind the reference to.                     --        [ See http://www.gotw.ca/resources/clcm.htm for info about ]        [ comp.lang.c++.moderated. First time posters: Do this! ]              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca