Search code examples
d

Create array of classes in d


It's my class

module figure;
import block; 
class Figure {
    Block[] body;
    this() {
        this.body ~= new Block();
    }
}

And I got "no identifier for declarator Block[]"

Block.d file

module block;

import std.stdio;

class Block {
  this() {
    writeln("In block.d");
  }
}

Solution

  • Oh, the word body is a keyword in D and thus cannot be used as a variable name. Try just about any other name, maybe body_ or just blocks or almost anything else and it will work.