Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
OK. So I got a program handling books and movies. Now I have 1 base class, and 2 that inherit from that.

When I try to run it I get "does not implement inherited abstract member"

baseclass:
C#
public abstract class saker
   {
       public string titel;
       public string genre;
       public int pris;
       public abstract string book(string t, string g, int p, int page);
       public abstract string movie(string t, string g, int p, double l);
       public abstract string visainfo();
   }



class film:
C#
class  film : saker
  {
          double langd;
          public override string movie(string t, string g, int p, double l)
          {
              this.langd = l;
              this.titel = t;
              this.genre = g;
              this.pris = p;
          }
          public override string visainfo()
          {
              string s;
              s = "Titel: " + titel + " Genre: " + genre + " Pris: " + pris + "kr Langd: " + langd;
              return s;
          }
  }



Now what am I doing wrong?

[Edit - Answer from OP moved here - Henry]
ahh no its there, i just forgot to add the code snippet
C#
public class bok : saker
{
    int sidor;
    public override string book(string t, string g, int p, int page)
    {
        this.sidor = page;
        this.titel = t;
        this.genre = g;
        this.pris = p;
    }
    public override string visainfo()
    {
        string s;
        s = "Titel: " + titel + " Genre: " + genre + " Pris: " + pris + "kr Sidor: " + sidor;
        return s;
    }
}


[/Edit]
Posted
Updated 16-Apr-18 21:33pm
v3

You missed book, that needs to be implemented too.

Based on your updated question, you cannot implement the abstract methods over multiple classes where no single class implements all of them. That's not how it works. Every derived class needs to implement all the abstract methods from the base class.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 9-Feb-11 12:49pm    
My 5. Borrowed a book -- don't forget to put back!
--SA
Nish Nishant 9-Feb-11 12:50pm    
:-)
Sandeep Mewara 9-Feb-11 12:52pm    
Yep! Right. 5!
Your saker class has three abstract members. You have to implement all three in each descendant.

So your Movie class must implement Book as well as Movie and your Book class must implement Movie as well as Book.

It looks like you need to redesign your saker class.
 
Share this answer
 
Comments
splyez 9-Feb-11 12:43pm    
i c, ill look into that, yeah im not sure this is the way to go but
Nish Nishant 9-Feb-11 12:44pm    
Voted 5, Henry. Good explanation.
Sergey Alexandrovich Kryukov 9-Feb-11 12:48pm    
Yes, tell them "you have to!". My 5.
--SA
Sandeep Mewara 9-Feb-11 12:51pm    
Simple and straight! 5!
Here's an alternate design suggestion:

C#
public interface IBook
{
    string book(string t, string g, int p, int page);
}
interface IMovie
{
    string movie(string t, string g, int p, double l);
}
public abstract class saker
{
    public string titel;
    public string genre;
    public int pris;
    public abstract string visainfo();
}
public class Book : saker, IBook
{
    public override string visainfo()
    {
        throw new NotImplementedException();
    }
    public string book(string t, string g, int p, int page)
    {
        throw new NotImplementedException();
    }
}
public class Movie : saker, IMovie
{
    public override string visainfo()
    {
        throw new NotImplementedException();
    }
    public string movie(string t, string g, int p, double l)
    {
        throw new NotImplementedException();
    }
}
 
Share this answer
 
right click on base class (after :) while deriving into derived class and then select implement, then it will create dummy method[s] in derived class according to your abstract class methods signatures.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900