problem in inheritence

erorr in child class.
Error 1 error C2512: 'Circle_computations' : no appropriate default constructor available
Error 4 error C2296: '*' : illegal, left operand has type 'void'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  #include<iostream>
using namespace std;

class Circle_computations
{

public:
	double area,circumference,radius,pi;
	
public:
	
  Circle_computations(double radi)
{
pi = 3.14;
radius=radi;


}

void c_area()
{

area = pi*radius*radius;
 // cout<<"****The  Area OF The Circle  is****\n"<<area<<"\n";

}

void c_circumferunce()
{

circumference =2*pi*radius;
//cout<<"****The Circle Circumferunce is****\n"<<circumference<<"\n";
}

};

class Cylinder:public Circle_computations
{

protected:
	double height,volume,cyarea;

public:
	Cylinder(double h)
	
		//:Circle_computations(radi);
	{
		height=h;


	}

	void cy_area()
{
	cyarea=(2 * (Circle_computations::c_area()))+( c_circumferunce()* height) ;

}


void c_volume()
{
	volume = (Circle_computations::c_area())* height;


}

















};


void main()

{
double r,heigh_t;
cout<<"**Please Enter The Radius First** \n";
cin>> r;
cout<<"**Please Enter The height** \n";
cin>>heigh_t;

Circle_computations  compute(r);
Cylinder computecylider(heigh_t);
cout<<"****The  Area OF The Circle  is****\n";
compute.c_area();
cout<<"\n";
cout<<"****The Circle Circumferunce is****\n";
compute.c_circumferunce();
cout<<"\n";
cout<<"****The cylinder surface  Area   is****\n";
computecylider.cy_area();
cout<<"\n";
cout<<"****The cylinder volume   is****\n";
computecylider.c_volume();
cout<<"\n";
Error 1 error C2512: 'Circle_computations' : no appropriate default constructor available

Circle_computations has an explicit constructor Circle_computations(double)
and therefore the compiler does not generate default constructor.

You have commented out a call to constructor on line 46. Why?

Error 4 error C2296: '*' : illegal, left operand has type 'void'
1
2
3
void Circle_computations::c_area();

volume = (Circle_computations::c_area())* height;

c_area() is a function that returns void. Therefore, you are trying to evaluate
volume = void * height;
That does not compute.
thank you i correct the error but there is rubbish values
#include<iostream>
using namespace std;

class Circle_computations
{

public:
double area,circumference,radius,pi;

public:


Circle_computations()
{
}
Circle_computations(double radi)
{
pi = 3.14;
radius=radi;


}

double c_area()
{

area = pi*radius*radius;
return area;

}

double c_circumferunce()
{

circumference =2*pi*radius;
return circumference;

}

};

class Cylinder:public Circle_computations
{

protected:
double height,volume,cyarea;

public:
Cylinder(double h)
{



height=h;


}

double cy_area()
{
cyarea=(2 * (Circle_computations::c_area()))+( c_circumferunce()* height) ;


}


double c_volume()
{
volume = (Circle_computations::c_area())* height;

return volume;

}

};


int main()

{
double r,heigh_t;
cout<<"**Please Enter The Radius First** \n";
cin>> r;
cout<<"**Please Enter The height** \n";
cin>>heigh_t;

Circle_computations compute(r);
Cylinder computecylider(heigh_t);

cout<<compute.c_area();
cout<<"\n";
cout<<"****The Circle Circumferunce is****\n";
cout<<compute.c_circumferunce();
cout<<"\n";
cout<<"****The cylinder surface Area is****\n";
cout<<computecylider.cy_area();
cout<<"\n";
cout<<"****The cylinder volume is****\n";
cout<<computecylider.c_volume();
cout<<"\n";



int g;
cin>>g;
}
There are two errors here.

The more obvious one is that you omitted the return statement from cy_area().

The more subtle one is that Cylinder's computations depend on Circle's c_area() and c_circumference(), which in turn use Circle's radius member.
But you never initialize it when you construct Cylinder.

The best solution is to call Circle's constructor in the member initializer list.

1
2
3
4
5
Cylinder(double r, double h) :
    Circle_computations(r)
{
    height = h;
}
Last edited on
Topic archived. No new replies allowed.