2010-03-16 96 views
0

我得到了一些错误说法:简单的继承问题

“名称‘标题’不存在于它的当前背景下” “名称‘作者’不存在于它的当前背景下” “这个名字“流派”不存在于它的当前背景下” ‘名称‘页’不存在于它的当前语境’

using System; 
using System.Collections.Generic; 
using System.Text; 

namespace ReadingMaterials 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 

     } 

     public class Basic 
     { 
      protected string Title; 
      protected string Author; 
      protected string Genre; 
      protected int Pages; 

      public Basic(string title, string author, string genre, int pages) 
      { 
       Title = title; 
       Author = author; 
       Pages = pages; 
       Genre = genre; 
      } 

      public int PageCount 
      { 
       get { return Pages; } 
       set { Pages = value; } 
      } 

      public string GenreType 
      { 
       get { return Genre; } 
       set { Genre = value; } 
      } 

      public string AuthorType 
      { 
       get { return Author; } 
       set { Author = value; } 
      } 

      public string TitleName 
      { 
       get { return Title; } 
       set { Title = value; } 
      } 
     } 

     public class Book : Basic 
     { 
      protected bool Hardcover; 

      public Book(bool hardcover) 
       : base(title, author, genre, pages) 
      { 
       Hardcover = hardcover; 
      } 

      public bool IsHardcover 
      { 
       get { return Hardcover; } 
       set { Hardcover = value; } 
      } 
     } 


    } 
} 

缺少什么我在这里?提前致谢。

回答

13

在您的Book的构造函数中,您期望使用什么值的title,author,genre和pages?你期望它们被传入构造函数吗?如果是这样,您需要修改您的Book构造函数,使其看起来像这样:

public Book(string title, string author, string genre, int pages, bool hardcover) 
    : base(title, author, genre, pages) 
{ 
    Hardcover = hardcover; 
} 
+0

谢谢先生!这工作=] – Stradigos 2010-03-16 04:20:05

0

您将不得不将成员变量传递给派生类,然后使用它们来初始化基类。