home bbs files messages ]

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,251 of 33,346   
   SG to Robert Simpson   
   Re: Dereferencing pointer as argument to   
   30 Oct 13 09:35:31   
   
   From: s.gesemann@googlemail.com   
      
   On Wednesday, October 30, 2013 1:00:02 AM UTC+1, 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?   
      
   If it's not a null pointer, i don't see anything wrong with it.   
      
   > E.g.   
   >   
   > void myfunc( Widget& w );   
   >   
   > std::unique_ptr< Widget > mywidget;   
   >   
   > myfunc( *mywidget.get() );   
      
   Well, here, mywidget.get() is a null pointer. But let's assume that   
   somewhere between defining mywidget and the function call, you make   
   mywidget to point to something, then, yes, this is perfectly fine.   
   Instead of   
      
     myfunc(*mywidget.get());   
      
   you could have also written   
      
     myfunc(*mywidget);   
      
   > I have written this in my code, but I believe that there is probably   
   > a better solution.   
      
   What is the problem?   
      
      
   --   
         [ 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