Re: Is it a bad idea to define private: as public: ?
On 8/25/2013 2:43 PM, DeMarcus wrote:
// main.cpp
#include <iostream>
#define protected public
#define private public
#include "PrintClass.h"
// PrintClass.h
#include <string>
....
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! ]