BitArray in custom class & initialize it in ctor with arguments

bearophile bearophileHUGS at lycos.com
Sat Mar 22 03:02:38 PDT 2014


MarisaLovesUsAll:

> Hi! I need to use array of bits in my custom class. I tried to
> add std.bitmanip.BitArray as field, but got a strange error. 
> What
> am I doing wrong?
>
> import std.bitmanip;
> class Scene
> {
>      BitArray collisionMap;
>      this(int w, int h)
>      {
>          collisionMap.init([0,0,0]);
>      }
> }
>
> C:\D\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d
> line 606
> Error: btr cannot be interpreted at compile time, because it has
> no available source code

To me this program compiles:


import std.bitmanip;

class Scene {
      BitArray collisionMap;
      this(int w, int h) {
          collisionMap.init([0,0,0]);
      }
}
void main() {}


Errors like "btr cannot be interpreted at compile time" mean that 
you are trying to run at compile-time something that can only run 
at run-time. So are you using enums or static immutables or 
static constructors or something like that?

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list