Private visible?
Lucas Goss
lgoss007 at gmail.com
Fri Jul 14 07:20:25 PDT 2006
Walter Bright wrote:
>
> Sometimes it is valuable to be able to say "you can't do this operation
> with this type". I don't see why this ability should be restricted to C++.
Can someone come up with an example or explain why this would be
valuable? To make sure we're on the same page, we're talking about:
----
class Base {
public:
virtual int Number() = 0;
};
...
class Child : public Base {
private:
int Number() { return 1; }
};
...
Child c;
int num = c.Number(); //error: cannot access private member
Child* cp = new Child();
num = cp->Number(); //error: cannot access private member
Base* bp = new Child();
num = bp->Number(); // num = 1
----
Is there an example where you can't subvert the poison? In this case
can't we get a pointer to the base class which returns what the child
class didn't want to give us (private Number)?
...Added to wiki to get better overview (it's easier for me to see
rather than jumping all over the newsgroup. Feel free to edit and
consolidate views into concrete and concise arguments. I'm starting to
feel like a secretary... :)
http://www.prowiki.org/wiki4d/wiki.cgi?PrivateIssues
Lucas
More information about the Digitalmars-d
mailing list