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 32,935 of 33,346   
   =?ISO-8859-1?Q?=D6=F6_Tiib?= to DeMarcus   
   Re: Can I overload with unused arguments   
   14 Mar 13 07:17:26   
   
   From: ootiib@hot.ee   
      
   On Thursday, 14 March 2013 13:35:05 UTC+2, DeMarcus  wrote:   
   > On 2013-03-13 17:35, Öö Tiib wrote:   
   > > On Wednesday, 13 March 2013 00:50:06 UTC+2, DeMarcus  wrote:   
   > > If it is dynamic polymorphism or dynamic dispatch then get out of   
   > > immersion of nullptr. Make a polymorphic smart pointer that instead   
   > > of nullptr uses pointer to static "MissingEntertainer" object that   
   > > *implements* the interface of Entertainer (just does nothing). Such   
   > > pointer can then never be nullptr, can be always dereferenced etc.   
   > > I'd call it as robust_pointer. :-)   
   >   
   > I agree your solution is better, but you can still accidently provide   
   > nullptr, right?   
      
   Because of new loose semantics of list-initializes I currently seem to   
   make all constructors besides default, copy and move 'explicit'.   
      
   With smart pointers I additionally tend to have factory functions   
   and prefer those when creating the pointers:   
      
      template   
      robust_ptr make_robust(/*variadic function parameters*/)   
      {/*usual stuff*/ return ret; }   
      
      typedef EntertainerPtr robust_ptr;   
      
   That makes it quite hard that nullptr sneaks in from somewhere   
   silently and if it comes explicitly from front doors then it will be   
   converted into MissingEntertainer*.   
      
   > So I'm still wondering, in order to prevent nullptr to   
   > be used, is it good practice to do this?   
   >   
   > void watchShow( std::nullptr_t ) = delete;   
      
   But the EntertainerPtr can't never be nullptr.   
   You will have only that:   
      
      void watchShow( Entertainer& );   
      
   Usage is like that:   
      
       Audience a;   
       EntertainerPtr p; //default constructs to MissingEntertainer*   
       a.watchShow( *p );   
      
   Works like charm.   
      
      
   --   
         [ 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