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,176 of 33,346   
   Balog Pal to DeMarcus   
   Re: Is it a bad idea to define private:    
   25 Aug 13 18:56:42   
   
   From: pasa@lib.hu   
      
   On 8/25/2013 2:43 PM, DeMarcus wrote:   
   >   
   > // main.cpp   
   > #include    
   >   
   > #define protected public   
   > #define private public   
   >   
   > #include "PrintClass.h"   
      
   > // PrintClass.h   
   > #include    
   >   
   ...   
      
   This puts the program into undefined behavior land. As any program that   
   #defines any keyword and then includes a any standard header.   
      
   You can salvage your idea if you take care to have the definition   
   applied only to stuff of home-made writing, and make sure you don't link   
   with anything compiled separately to avoid an ODR violation.   
      
      
   > void whiteBoxTest()   
   > {   
   >      PrintClass pc;   
   >      std::cout << pc.privatePrinting() << std::endl;   
   > }   
   >   
   > int main()   
   > {   
   >      whiteBoxTest();   
   >      return 0;   
   > }   
   >   
   > My question is: is this a bad idea?   
      
   Too shaky for my taste for sure.   
      
   You can use way simpler tricks to access private parts in tests. My   
   classes have a line 'friend struct Tester;'.  And Tester is something   
   not existing in the real system, so no effect, but in the test suite you   
   can create a so-named class and use it to deal with the private state.   
      
   > I can't really see the bad consequences but I guess things like SFINAE   
   > could break.   
      
   Hm, you seem not care too much about defined behavior that all tests are   
   normally based on?   
      
      
   --   
         [ 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