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. Class inheritance compile error

Class inheritance compile error

Scheduled Pinned Locked Moved C#
oophelpquestion
3 Posts 2 Posters 0 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.
  • E Offline
    E Offline
    ekareem
    wrote on last edited by
    #1

    Could someone point out why there is an error here? Thanks. class BankAccount { decimal m_ID; public BankAccount(string ID) { m_ID = 0; } } class SavingsAccount : BankAccount { decimal m_ID; //***Compile Error at the following line: No overload for method 'BankAccount' takes '0' arguments public SavingsAccount(string ID) { m_ID = 0; } }

    M 1 Reply Last reply
    0
    • E ekareem

      Could someone point out why there is an error here? Thanks. class BankAccount { decimal m_ID; public BankAccount(string ID) { m_ID = 0; } } class SavingsAccount : BankAccount { decimal m_ID; //***Compile Error at the following line: No overload for method 'BankAccount' takes '0' arguments public SavingsAccount(string ID) { m_ID = 0; } }

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Since the SavingsAccount ctor doesn't have an explicit call to the base class ctor, the compiler will insert a call to the default ctor (the one with no parameters). But there is no such ctor, so you get the error. You need to add the call to the initializer list: public SavingsAccount(string ID) : base(ID) { ... }

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      E 1 Reply Last reply
      0
      • M Michael Dunn

        Since the SavingsAccount ctor doesn't have an explicit call to the base class ctor, the compiler will insert a call to the default ctor (the one with no parameters). But there is no such ctor, so you get the error. You need to add the call to the initializer list: public SavingsAccount(string ID) : base(ID) { ... }

        --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

        E Offline
        E Offline
        ekareem
        wrote on last edited by
        #3

        Thanks much.

        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