Thread overview
Object
Jun 13, 2011
Lloyd Dupont
Jun 13, 2011
Jonathan M Davis
Jun 13, 2011
Jonathan M Davis
Jun 13, 2011
Lloyd Dupont
June 13, 2011
I have problem with "Object"

for example this doesn't compile:
===
Object o;
o = "";
===
with error: cannot implicitly convert expression ("") of type string to object.Object

or this also failed to compile:
===
class Foo
{
public:
   Object foo, bar, snafu;

   override const bool opEquals(Object t) {
       auto other = cast(Foo)t;
       if (!other)
           return false;
       return
           other.foo == foo
           && other.bar == bar
           && other.snafu == snafu
           ;
   }
}
====
with error such as:  function object.opEquals (Object lhs, Object rhs) is not callable using argument types (Object,const(Object))

Any tip?

June 13, 2011
On 2011-06-12 22:25, Lloyd Dupont wrote:
> I have problem with "Object"
> 
> for example this doesn't compile:
> ===
> Object o;
> o = "";
> ===
> with error: cannot implicitly convert expression ("") of type string to
> object.Object

Object is the base class of all classes. Nothing which is not a class is an Object. Strings are arrays, and you can't assign an array to an Object reference - or any other class reference for that matter.

> or this also failed to compile:
> ===
> class Foo
> {
> public:
>     Object foo, bar, snafu;
> 
>     override const bool opEquals(Object t) {
>         auto other = cast(Foo)t;
>         if (!other)
>             return false;
>         return
>             other.foo == foo
>             && other.bar == bar
>             && other.snafu == snafu
>             ;
>     }
> }
> ====
> with error such as:  function object.opEquals (Object lhs, Object rhs) is
> not callable using argument types (Object,const(Object))
> 
> Any tip?

June 13, 2011
On 2011-06-12 22:37, Jonathan M Davis wrote:
> On 2011-06-12 22:25, Lloyd Dupont wrote:
> > I have problem with "Object"
> > 
> > for example this doesn't compile:
> > ===
> > Object o;
> > o = "";
> > ===
> > with error: cannot implicitly convert expression ("") of type string to
> > object.Object
> 
> Object is the base class of all classes. Nothing which is not a class is an Object. Strings are arrays, and you can't assign an array to an Object reference - or any other class reference for that matter.
> 
> > or this also failed to compile:
> > ===
> > class Foo
> > {
> > 
> > public:
> >     Object foo, bar, snafu;
> > 
> >     override const bool opEquals(Object t) {
> > 
> >         auto other = cast(Foo)t;
> >         if (!other)
> > 
> >             return false;
> > 
> >         return
> > 
> >             other.foo == foo
> >             && other.bar == bar
> >             && other.snafu == snafu
> >             ;
> > 
> >     }
> > 
> > }
> > ====
> > with error such as:  function object.opEquals (Object lhs, Object rhs) is
> > not callable using argument types (Object,const(Object))
> > 
> > Any tip?

Blast it. I accidentally sent that before I was finished.

Object is not currently const-correct: http://d.puremagic.com/issues/show_bug.cgi?id=1824

As a result, a number of basic functions do not currently work with const objects. So, making opEquals const means that it's not going to work. It sucks, but until Object is fixed to be const-correct, that's the way it goes. Fixing the major problems with const and immutable are next on the todo list (after Walter has finished fixing issues with destructors for temporaries). So, hopefully, it won't be too much longer before opEquals is properly const, but for now, that doesn't work.

- Jonathan M Davis
June 13, 2011
I see.... mm....
Thanks for the info!

"Jonathan M Davis"  wrote in message news:mailman.866.1307943671.14074.digitalmars-d-learn@puremagic.com...

Object is not currently const-correct:
http://d.puremagic.com/issues/show_bug.cgi?id=1824

As a result, a number of basic functions do not currently work with const
objects. So, making opEquals const means that it's not going to work. It
sucks, but until Object is fixed to be const-correct, that's the way it goes.