Object

Jonathan M Davis jmdavisProg at gmx.com
Sun Jun 12 22:37:44 PDT 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?



More information about the Digitalmars-d-learn mailing list