Two question about array
Alex
faint_u at 163.com
Mon Dec 31 05:23:48 PST 2007
I'm trying to use Variant but got error message with the following code:
-------------------------------------------
import std.variant;
void main()
{
Variant v;
v = 4;
}
-----------------------------
error message:
E:\Tools\Lang\D>dmd test.d
e:\Tools\Lang\d\dmd\bin\..\..\dm\bin\link.exe test,,,user32+kernel32/noi;
OPTLINK (R) for Win32 Release 8.00.1
Copyright (C) Digital Mars 1989-2004 All rights reserved.
test.obj(test)
Error 42: Symbol Undefined _D3std7variant17__T8VariantNVk20Z8VariantN4typeMFZC8TypeInfo
test.obj(test)
Error 42: Symbol Undefined _D3std7variant17__T8VariantNVk20Z8VariantN6__initZ
--- errorlevel 2
What's the problem?
Jarrett Billingsley Wrote:
> "Alex" <faint_u at 163.com> wrote in message
> news:fl88r1$1olc$1 at digitalmars.com...
> > 1. Is array a class derived from Object? If yes, why i get error message
> > with the following code:
> > int[] array;
> > Object obj = array;
> > If not, is there any general type can represent either an Integer, or an
> > Array? Or a character string?
>
> Arrays are not objects. They are arrays :) They are their own type and are
> not related to any other type.
>
> If you need an integer or an array you need some kind of variant type. If
> you're using Tango, there's tango.core.Variant; if you're using Phobos with
> D1, there's std.boxer; and Phobos with D2 has deprecated std.boxer in favor
> of std.variant.
>
> > 2. simpleArray.length = simpleArray.length * 2 can pass the compile but
> > simpleArray.length *= 2 can't. The compiler complains "simpleArray.length
> > is not an lvalue", what's the problem?
>
> It's because these are really syntactic sugar for function calls.
> "simpleArray.length = 5" is the same as "simpleArray.length(5)". If you try
> to do "simpleArray.length *= 2" you're basically writing
> "simpleArray.length() *= 2", which obviously makes no sense. The same thing
> would happen with class properties.
>
> It's dumb. I know.
>
>
More information about the Digitalmars-d-learn
mailing list