February 05, 2003 member access not spotted by the compiler | ||||
---|---|---|---|---|
| ||||
if you have a derived class with a private member that hides a public or protected base member you get and access voilation at runtime without any compiler warnings; also it seem allow able to have a protected member in a derived class that is public in the base class (all you need to acces the method is a cast(base)). class base { public: this() { printf( "base::this(){" ); init(); printf( "}base::this()" ); } abstract void init(); } class derv : base { private: // Access voilation //protected: // works why ? //public: // works void init() { printf( "-init-" ); } } int main( char[][] args ) { printf( "main{" ); derv d = new derv(); printf( "}main\n" ); return 0; } |
February 05, 2003 Re: member access not spotted by the compiler | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | Unfortunatly I cannot shed light on your question, however I would like to know what is the point of private, if you can do this? class base { public: this() { init(); } abstract void init(); } class derv : base { private: // Access voilation int test; public: // works void init() { printf( "-init-", test ); } } int main( char[][] args ) { derv d = new derv(); d.test = 5; // should this work? printf("[%d]", d.test); return 0; } |
Copyright © 1999-2021 by the D Language Foundation