Const again

naryl cy at ngs.ru
Thu Jan 24 17:05:00 PST 2008


Is there a way to make something like this work in D 2.0?

clone is supposed to make a new shallow copy of it's object:

  interface Cloneable
  {
      const Cloneable clone();
  }

  class Demo : Cloneable
  {
      public :
          this(){}

          this( Demo reference )
          {
              reference_ = reference;
          }

          override const Demo clone() {
              return new Demo( reference_ );
          }
      private:
          Demo reference_;
  }

  void main()
  {
      auto a = new Demo(new Demo);
      auto b = a.clone();
  }

The method clone must be const and there must be a non-const constructor  
in Demo.


More information about the Digitalmars-d-learn mailing list