ชื่อ Word ไม่ใช่คลาส/ประเภท

ฉันมีสามคลาสใน Dart ดังที่แสดงด้านล่าง:

นิดหน่อย:

part of CB_Crypto;

class Bit {
  bool _state = false,
       _sympathetic = false;
  int _alignment = 0;

  Bit(List args) {
    _state = args[0];
    _sympathetic = args[1];
    _alignment = args[2];
  }

  bool state() => _state;

  bool not() => _state = !_state;

  bool set(bool state) => _state = state;

  bool isSympathetic() =>  _sympathetic;

  operator &(Bit b) => state() && b.state();

  operator |(Bit b) => state() || b.state();
}

คำ:

part of CB_Crypto;

class Word {
  List<Bit> _bits = [];

  Word(List<List> bits) {
    bits.forEach((bit) => _bits.add(new Bit(bit)));
  }

  bool not(int i) => _bits[i].not();

  void notAll() => _bits.forEach((bit) => bit.not());

}

โต๊ะ:

part of CB_Crypto;

class Table {
  List<Word> _words;

  Word(List<List> words) {
    words.forEach((word) => _words.add(new Word(word)));
  }
}

ทั้งหมดนี้อยู่ในไฟล์ที่แตกต่างกันและเป็นส่วนหนึ่งของไลบรารีเดียวกัน อย่างไรก็ตาม ฉันได้รับคำเตือนจาก Dartium ในคลาส Table สำหรับการใช้ Word เป็นประเภทและพยายามสร้างอินสแตนซ์ของวัตถุ Word: the name "Word" is not a (type/class) and cannot be used as a parametrized type

ฉันเชื่อว่าฉันเขียนคลาส Word คล้ายกับคลาส Bit และนั่นไม่ทำให้เกิดข้อผิดพลาดเมื่อใช้ใน Table เนื่องจากมีการใช้ Word ฉันพลาดอะไรไปรึเปล่า?


person Melvin Sowah    schedule 15.06.2014    source แหล่งที่มา
comment
โปรดแสดงรหัสที่ทำให้เกิดข้อผิดพลาดนี้ได้ไหม   -  person Robert    schedule 15.06.2014
comment
ฉันสงสัยว่าวิธีนี้ได้ผล: Word(List<List> words) { - เพื่อความเข้าใจที่ดีขึ้น คุณควรพิมพ์รายการ (ด้านใน) ให้เรา   -  person Robert    schedule 15.06.2014
comment
คุณได้เพิ่ม part "file.dart" สำหรับแต่ละส่วนในห้องสมุดของคุณหรือไม่?   -  person Günter Zöchbauer    schedule 15.06.2014
comment
@Robert รหัสที่ส่งข้อผิดพลาดคือคลาส Table (คำจำกัดความรายการและ forEach loop   -  person Melvin Sowah    schedule 15.06.2014
comment
@ GünterZöchbauer ใช่ฉันทำ   -  person Melvin Sowah    schedule 15.06.2014


คำตอบ (1)


คุณกำลังใช้ Word เป็นตัวสร้างภายในคลาสตาราง

Word(List<List> words) {
  words.forEach((word) => _words.add(new Word(word)));
}

Constructor ของคุณควรเป็น Table จากรูปลักษณ์ของมัน

Table(List<List> words) {
  words.forEach((word) => _words.add(new Word(word)));
}
person Kevin Sheehan    schedule 15.06.2014
comment
ฉันไม่อยากจะเชื่อเลยว่าฉันไม่ได้สังเกตเห็นสิ่งนั้น ฉันคัดลอกและวางโค้ดของ Table จาก Word และเปลี่ยนชื่อทั้งหมดเนื่องจากโดยพื้นฐานแล้วเหมือนกัน ฉันเดาว่าฉันพลาดไปหนึ่ง :) ขอบคุณ - person Melvin Sowah; 15.06.2014