Re: Sanity check: public/private
Alf P. Steinbach wrote:
* Carlos Moreno:
I'm not saying that #defining private as public is the way
to run test protocols; I simply think that it is an
interesting alternative, that can be quite useful in certain
situations -- I wanted to know if I should expect the trick
to work in the general case.
From a practical point of view I think so.
Provided he's not using private inheritance. (Even then, I'd be
surprised if he had a problem unless private inheritance was
used in the exception hierarchy. And only in exceptional cases
then.)
From a formal point of view you're prohibited from defining a
macro with the same name as a keyword if any standard library
headers are included.
An alternative is to directly support testing in the classes
(it can be as simple as a "friend" declaration).
This is what I've done (or rather seen done) in the past. Every
class X has a declaration: friend class TestX. Anytime you want
to access a private member in the test, you just add a function
to TestX (which, of course, as a class only exists for this
reason, so we don't care that it isn't well designed:-)).
--
James Kanze (Gabi Software) email: kanze.james@neuf.fr
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]