-
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;
}
-
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).
-
:(
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.....