Click here to Skip to main content
15,888,610 members
Home / Discussions / C#
   

C#

 
GeneralRe: VS 2010 No method to override error Pin
Deborah Palmer McCain13-Dec-11 16:27
Deborah Palmer McCain13-Dec-11 16:27 
GeneralRe: VS 2010 No method to override error Pin
PIEBALDconsult14-Dec-11 1:58
mvePIEBALDconsult14-Dec-11 1:58 
AnswerRe: VS 2010 No method to override error Pin
BillWoodruff13-Dec-11 15:43
professionalBillWoodruff13-Dec-11 15:43 
GeneralRe: VS 2010 No method to override error Pin
Deborah Palmer McCain13-Dec-11 16:23
Deborah Palmer McCain13-Dec-11 16:23 
AnswerRe: VS 2010 No method to override error Pin
Luc Pattyn13-Dec-11 19:08
sitebuilderLuc Pattyn13-Dec-11 19:08 
GeneralRe: VS 2010 No method to override error Pin
PIEBALDconsult14-Dec-11 1:57
mvePIEBALDconsult14-Dec-11 1:57 
GeneralRe: VS 2010 No method to override error Pin
Deborah Palmer McCain14-Dec-11 10:10
Deborah Palmer McCain14-Dec-11 10:10 
AnswerRe: VS 2010 No method to override error [Long Post] Pin
Keith Barrow13-Dec-11 22:09
professionalKeith Barrow13-Dec-11 22:09 
Deborah Palmer McCain wrote:
Should this be simple deduction and logical?
Pretty much always in IT

To work this through, a basic [incomplete] definition of a few keywords is probably helpful:

abstract: Whatever is declared abstract is missing or incomplete. A the class level this means that the class can't be instantiated directly, so it must be subclassed before use. For members of the class marked abstract you don't declare a body (e.g. <codelang="cs">public abstract int f();), and you must override in a subclass unless the subclass is also abstract. All abstract members are inherently virtual
virtual This isn't in the example, but it marks a method as being overridable, that is subclasses can (as opposed to must) override them in a non-abstract subclass.
override Members marked as overridden "replace" the superclass's virtual/abstract method. This can be summed up with the following code:
C#
public abstract class Foo
{
    public abstract void Bar();
}

public abstract class Baz : Foo
{
    //Not-necessary to implement Bar() as Baz is also abstract
    public virtual void Quux()
    {
    }

    public virtual void Grault()
    {
    }
}

public class Corge : Foo
{
    public override void Bar()
    {
        //As this is non-abstract it must implement Bar()
    }

    public override void Quux()
    {
        //Overides virtual method
    }

    //Not-necessary to override Grault, but it is possible as per Quux().
}


Now to your problem. "No method to override", the word override only appears once, so we know this line is the problem:

public override int f()
{
...
}


So what are the preconditions for overriding? The method must override a method in a superclass that is marked as abstract or virtual. The method apparently being overridden is marked as abstract. It put italics on "apparently" as, in reality, MyClass2 doesn't have a superclass (as PiebaldConsultant has replied):

abstract public class MyClass2

the fix is now easy:

abstract public class MyClass2: MyClass1


GeneralRe: VS 2010 No method to override error [Long Post] Pin
Deborah Palmer McCain14-Dec-11 10:03
Deborah Palmer McCain14-Dec-11 10:03 
AnswerRe: VS 2010 No method to override error Pin
Richard MacCutchan13-Dec-11 22:23
mveRichard MacCutchan13-Dec-11 22:23 
GeneralRe: VS 2010 No method to override error Pin
prasun.r14-Dec-11 1:23
prasun.r14-Dec-11 1:23 
GeneralRe: VS 2010 No method to override error Pin
Deborah Palmer McCain14-Dec-11 10:04
Deborah Palmer McCain14-Dec-11 10:04 
GeneralRe: VS 2010 No method to override error Pin
Richard MacCutchan14-Dec-11 11:43
mveRichard MacCutchan14-Dec-11 11:43 
Questionchat software Pin
om_metab13-Dec-11 9:09
om_metab13-Dec-11 9:09 
AnswerRe: chat software Pin
Dalek Dave13-Dec-11 12:43
professionalDalek Dave13-Dec-11 12:43 
AnswerRe: chat software Pin
Keith Barrow13-Dec-11 22:33
professionalKeith Barrow13-Dec-11 22:33 
GeneralRe: chat software Pin
om_metab13-Dec-11 23:51
om_metab13-Dec-11 23:51 
AnswerRe: chat software Pin
BobJanova13-Dec-11 22:47
BobJanova13-Dec-11 22:47 
GeneralRe: chat software Pin
om_metab13-Dec-11 23:39
om_metab13-Dec-11 23:39 
GeneralRe: chat software Pin
BobJanova14-Dec-11 1:05
BobJanova14-Dec-11 1:05 
GeneralRe: chat software Pin
om_metab15-Dec-11 8:57
om_metab15-Dec-11 8:57 
QuestionReporting Service Pin
eddieangel13-Dec-11 7:33
eddieangel13-Dec-11 7:33 
AnswerRe: Reporting Service Pin
jschell13-Dec-11 8:45
jschell13-Dec-11 8:45 
AnswerRe: Reporting Service Pin
BobJanova13-Dec-11 22:54
BobJanova13-Dec-11 22:54 
QuestionHow can i display msg file to user in Reply/Forwrd/ReplyAll mode similar to outlook mailitem ? Pin
Tanuja12313-Dec-11 3:22
Tanuja12313-Dec-11 3:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.