digitalmars.D.learn - BitArray in custom class & initialize it in ctor with arguments
- MarisaLovesUsAll (33/33) Mar 22 2014 Hi! I need to use array of bits in my custom class. I tried to
- bearophile (16/33) Mar 22 2014 To me this program compiles:
- MarisaLovesUsAll (7/43) Mar 23 2014 Thanks for help! It was static(?) ctor, I had been trying to
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 If I use collisionMap.length(w*h), I get: C:\D\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d line 554 Error: non-constant expression [0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, And if I use BitArray in default ctor ( this() ), or in other function in class, or in main function, all is OK. But I need only ctor with arguments that initialize the BitArray with '0' and sets 'w*h' length. DMD version 2.065.0 Sorry for bad English.
Mar 22 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 codeTo 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
Mar 22 2014
On Saturday, 22 March 2014 at 10:02:39 UTC, bearophile wrote:MarisaLovesUsAll:Thanks for help! It was static(?) ctor, I had been trying to create Scene from another class via class App { Scene scene = new Scene(13,10); }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 codeTo 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
Mar 23 2014