Inheritance:

This is a discussion on Inheritance: within the C++ Programming forums, part of the General Programming Boards category; I am getting runtime errors that say: Code: Linker (id) Error "circle::circle()" reference from: Linker (id) Error "cylinder::cylinder()",reference from: Code: ...

  1. #1
    Registered User
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    466

    Inheritance:

    I am getting runtime errors that say:

    Code:
    Linker (id) Error
    "circle::circle()" reference from:
    
    Linker (id) Error
    "cylinder::cylinder()",reference from:
    Code:
    #include <iostream>
    
    using namespace std;
    
    class circle {
        
    protected:
        double radius=1.0;
    
    public:
        circle();
        
        const double PI = 3.14;
        
        void setRadius(double a){
            radius=a;
        }
        
        double calcVal(){
            
            return PI*radius*radius;
        }
    };
    
    class cylinder : public circle {
    protected:
        int length;
        
    public:
        cylinder();
        
        double calcVal()
        {
            return length * circle::calcVal();
            
        }
        
        
    };
    
    int main()
    {
        double radius;
        
        cylinder v;
        circle c;
        
        cout<<"Enter the radius of the circle in question: "<<endl;
        cin>>radius;
        
        c.setRadius(radius);
       
        cout<<"The area of the circle is: "<<c.calcVal()<<endl;
        cout<<"The volume of the circle is:"<<v.calcVal()<<endl;
        
        
        
        return 0;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,632
    You forgot to define the default constructor for circle and cylinder.

    Note that the errors are not runtime errors. They are linker/link time errors. When you get such errors that mention "undefined reference" or something along those lines, look at the error message and see if you defined the function (or sometimes, check if you included the file containing the function definition in your project/build script).
    Last edited by laserlight; 11-09-2013 at 12:45 PM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    466


    This is the second time you had to remind me about this....

    I been programming for 9 hours today. I had to make a chess game and a address book with a bunch of switch statements. I think I should go lay down...

    Thank you laser light.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GDB and inheritance
    By markcole in forum C++ Programming
    Replies: 10
    Last Post: 02-04-2009, 08:19 AM
  2. Inheritance
    By Verdagon in forum C++ Programming
    Replies: 8
    Last Post: 06-12-2005, 10:58 AM
  3. Inheritance...
    By EvBladeRunnervE in forum C++ Programming
    Replies: 3
    Last Post: 08-26-2003, 01:13 PM
  4. Inheritance?
    By Krak in forum C++ Programming
    Replies: 3
    Last Post: 07-16-2003, 08:32 PM
  5. inheritance help...
    By tetra in forum C++ Programming
    Replies: 5
    Last Post: 05-12-2003, 07:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21