www.digitalmars.com         C & C++   DMDScript  

D - member access not spotted by the compiler

reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
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;
}
Feb 05 2003
parent "Andrew Edwards" <aedwards spamfreeamerica.com> writes:
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;
}
Feb 05 2003