Hiding class pointers -- was it a good idea?

Alex Burton alexibu at mac.com
Fri Aug 17 17:26:50 PDT 2007


Tristam MacDonald Wrote:

> Agreed, but I can't think of another language that supports this 
> definition of OOP (apart from 'mutable' under C++ - which is widely 
> regarded as a hack).
> 
> Alex Burton wrote:
> > By making all objects that an object has references to necessarily part of that object, the transitive const feature means that the only state relationship a class can have to another class is encapsulation.
> > 

And I totally agree that mutable is a hack.
But when a class has a *pointer* to another object in C++, I can choose whether to tell the compiler that the other object is part of the class or not.
In D all classes are referred to by pointers. And all pointers are assumed to mean part of (because of transitive const).

It is perfectly logical to disallow changing objects that are part of a const class.
I am having trouble figuring out how I am going to write code when I can't store a pointer to something in a class without it being interpreted as a part of relationship.

Clearly in the below code transitive const does not make sense. And does not allow me to describe reality. Which is what I need to do to write sensible code.

class Table
{
   Database mDatabase;
   const const(Data) getData()
   {
      mDatabase.lock();     //error cannot change the state of mDatabase even though it can be in no way thought of as part of Table
      ...
      mDatabase.unlock();
   }

};



More information about the Digitalmars-d mailing list