Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. VS 2010 No method to override error

VS 2010 No method to override error

Scheduled Pinned Locked Moved C#
helpvisual-studiotutorialquestion
15 Posts 7 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Deborah Palmer McCain

    // CS0115.cs
    namespace MyNamespace
    {
    abstract public class MyClass1
    {
    public abstract int f();
    }

    abstract public class MyClass2
    {
        public override int f()   // CS0115
        {
            return 0;
        }
    
        public static void Main()
        {
        }
    }
    

    }

    After reducing errors to 1, I received the error (named in the Subject line) on line 14 of my project "No method to override". The problem is, Line 14 is blank. When I went to MSDN, I found CS0115, but I don't know how to change it to work with my project. Should this be simple deduction and logical? Any help would be appreciated.

    B Offline
    B Offline
    BillWoodruff
    wrote on last edited by
    #3

    On this question: I think it would be helpful if you state your usage scenario here: what exactly are you trying to implement: how are the classes that implement these abstract classes going to use them ? An abstract class that does not inherit from some other class is not going to have anything inside it that you can override. If you changed your 'MyClass2' definition to this:

    abstract public class MyClass2: MyClass1
    {
    public override int f()
    {
    return 0;
    }

    public static void Main()
    {
    }
    

    }

    Now it will compile. But please note, that I am not sure this something you should do. By the way, I find it very weird to see a 'Main entry point for execution inside an abstract class. I'm curious what your intent is in putting it there. Override in "Abstract, Son of Abstract" ? I hope others on this forum, much more knowledgeable than I am regarding use of inheritance involving abstract classes, will comment on what it might mean for one abstract class to inherit from another abstract class: is this good (or common) practice ? The purpose of that is obscure ... to me.

    "For no man lives in the external truth among salts and acids, but in the warm, phantasmagoric chamber of his brain, with the painted windows and the storied wall." Robert Louis Stevenson

    D 1 Reply Last reply
    0
    • B BillWoodruff

      On this question: I think it would be helpful if you state your usage scenario here: what exactly are you trying to implement: how are the classes that implement these abstract classes going to use them ? An abstract class that does not inherit from some other class is not going to have anything inside it that you can override. If you changed your 'MyClass2' definition to this:

      abstract public class MyClass2: MyClass1
      {
      public override int f()
      {
      return 0;
      }

      public static void Main()
      {
      }
      

      }

      Now it will compile. But please note, that I am not sure this something you should do. By the way, I find it very weird to see a 'Main entry point for execution inside an abstract class. I'm curious what your intent is in putting it there. Override in "Abstract, Son of Abstract" ? I hope others on this forum, much more knowledgeable than I am regarding use of inheritance involving abstract classes, will comment on what it might mean for one abstract class to inherit from another abstract class: is this good (or common) practice ? The purpose of that is obscure ... to me.

      "For no man lives in the external truth among salts and acids, but in the warm, phantasmagoric chamber of his brain, with the painted windows and the storied wall." Robert Louis Stevenson

      D Offline
      D Offline
      Deborah Palmer McCain
      wrote on last edited by
      #4

      Thank you for your response, but the code I listed was the sample from MSDN, not mine. MSDN provided it as a way to fix the error in the compiler (CS0115)but I wasn't sure what to change to make it "my own". I questioned the abstract class, (like I would know?)...but MSDN indicated that the patch would activate CS0115 and fix the code error of "no method to override". As for today, the "chamber of my brain" is cooked in code. Thank you again for trying.

      L 1 Reply Last reply
      0
      • P PIEBALDconsult

        Perhaps you forgot to tell the compiler that MyClass2 is supposed to derive from MyClass1?

        D Offline
        D Offline
        Deborah Palmer McCain
        wrote on last edited by
        #5

        As I indicated to others who kindly tried to help, the given code is not mine, but rather the MSDN CS01150 to fix the error "no method to override". I just don't know how to change it, but will muddle through tomorrow. The error appears for a line which is blank...which threw me into a confused abyss. This is the final error on many lines of code, so, of course,it will give me the most trouble in fixing. I am just learning, so I truly appreciate the help.

        P 1 Reply Last reply
        0
        • D Deborah Palmer McCain

          Thank you for your response, but the code I listed was the sample from MSDN, not mine. MSDN provided it as a way to fix the error in the compiler (CS0115)but I wasn't sure what to change to make it "my own". I questioned the abstract class, (like I would know?)...but MSDN indicated that the patch would activate CS0115 and fix the code error of "no method to override". As for today, the "chamber of my brain" is cooked in code. Thank you again for trying.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #6

          The concept may be shocking and new to you, however even Microsoft once in a while includes a little bug in their code, not all sample code snippets are correct. This has become a fact of life, you'll have to learn and live with it. :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          P 1 Reply Last reply
          0
          • D Deborah Palmer McCain

            // CS0115.cs
            namespace MyNamespace
            {
            abstract public class MyClass1
            {
            public abstract int f();
            }

            abstract public class MyClass2
            {
                public override int f()   // CS0115
                {
                    return 0;
                }
            
                public static void Main()
                {
                }
            }
            

            }

            After reducing errors to 1, I received the error (named in the Subject line) on line 14 of my project "No method to override". The problem is, Line 14 is blank. When I went to MSDN, I found CS0115, but I don't know how to change it to work with my project. Should this be simple deduction and logical? Any help would be appreciated.

            K Offline
            K Offline
            Keith Barrow
            wrote on last edited by
            #7

            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. 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:

            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

            Sort of a cross between Lawrence of Arabia and Dilbert.[

            D 1 Reply Last reply
            0
            • D Deborah Palmer McCain

              // CS0115.cs
              namespace MyNamespace
              {
              abstract public class MyClass1
              {
              public abstract int f();
              }

              abstract public class MyClass2
              {
                  public override int f()   // CS0115
                  {
                      return 0;
                  }
              
                  public static void Main()
                  {
                  }
              }
              

              }

              After reducing errors to 1, I received the error (named in the Subject line) on line 14 of my project "No method to override". The problem is, Line 14 is blank. When I went to MSDN, I found CS0115, but I don't know how to change it to work with my project. Should this be simple deduction and logical? Any help would be appreciated.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #8

              Well you have copied the sample code from here[^] which has been specifically written to generate a CS0115 error. What other result were you expecting to get?

              Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

              P D 2 Replies Last reply
              0
              • L Lost User

                Well you have copied the sample code from here[^] which has been specifically written to generate a CS0115 error. What other result were you expecting to get?

                Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                P Offline
                P Offline
                prasun r
                wrote on last edited by
                #9

                Haha that's a good one 5/5

                1 Reply Last reply
                0
                • L Luc Pattyn

                  The concept may be shocking and new to you, however even Microsoft once in a while includes a little bug in their code, not all sample code snippets are correct. This has become a fact of life, you'll have to learn and live with it. :)

                  Luc Pattyn [My Articles] Nil Volentibus Arduum

                  P Online
                  P Online
                  PIEBALDconsult
                  wrote on last edited by
                  #10

                  No the code correctly demonstrates how to generate the error.

                  D 1 Reply Last reply
                  0
                  • D Deborah Palmer McCain

                    As I indicated to others who kindly tried to help, the given code is not mine, but rather the MSDN CS01150 to fix the error "no method to override". I just don't know how to change it, but will muddle through tomorrow. The error appears for a line which is blank...which threw me into a confused abyss. This is the final error on many lines of code, so, of course,it will give me the most trouble in fixing. I am just learning, so I truly appreciate the help.

                    P Online
                    P Online
                    PIEBALDconsult
                    wrote on last edited by
                    #11

                    So where is your code? We can't help you without it.

                    1 Reply Last reply
                    0
                    • K Keith Barrow

                      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. 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:

                      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

                      Sort of a cross between Lawrence of Arabia and Dilbert.[

                      D Offline
                      D Offline
                      Deborah Palmer McCain
                      wrote on last edited by
                      #12

                      Thank you for your detailed explanation of the issue. It helped alot, and even though the issue was resolved, your detailed assistance is appreciated.

                      1 Reply Last reply
                      0
                      • L Lost User

                        Well you have copied the sample code from here[^] which has been specifically written to generate a CS0115 error. What other result were you expecting to get?

                        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                        D Offline
                        D Offline
                        Deborah Palmer McCain
                        wrote on last edited by
                        #13

                        I plead ignorance (which is becoming less easy). There is now an arc in my learning curve.

                        L 1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          No the code correctly demonstrates how to generate the error.

                          D Offline
                          D Offline
                          Deborah Palmer McCain
                          wrote on last edited by
                          #14

                          At the risk of causing anyone to be rabid, why would one want to generate an error? Wouldn't someone go to MSDN for assistance? I probably should move to the rant page, as I am not posing legitimate issues.

                          1 Reply Last reply
                          0
                          • D Deborah Palmer McCain

                            I plead ignorance (which is becoming less easy). There is now an arc in my learning curve.

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #15

                            I usually plead senility, it works every time. ;)

                            Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups