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,911 of 33,346   
   Seungbeom Kim to Jerry   
   Re: Passing pointer to member objects   
   11 Mar 13 01:39:36   
   
   41d7577e   
   From: musiphil@bawi.org   
      
   On 2013-03-07 22:22, Jerry wrote:   
   >   
   > template   
   > R get(R* begin,R* end,char R::* m[20],const char * v)   
   > {   
   > ....   
   > }   
      
   That actually declares m as an 20-element array of pointers to   
   R-member char. The correct declaration would be "char (R::*m)[20]", a   
   pointer to R-member 20-element array of char.   
      
   >   
   > Well I could but how many functions do I need since the size of the   
   > array must be specified in the function signature?   
   >   
   > Is there any way to generically define this function so I can pass   
   > any structure member including char arrays of arbitrary length?   
      
   As Daniel Krügler suggested, you can use templates. Let me add that   
   comparing built-in arrays by a simple == doesn't work and that you'll   
   probably want to use std::strcmp.   
      
   On the other hand, if you had used std::string in the first place, you   
   wouldn't have had to worry about this problem at all.   
      
   --   
   Seungbeom Kim   
      
      
         [ 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