error C2512: 'date' : no appropriate default constructor available

Hi, I am getting a very weird error about constructors and I do not know why? When The error occurs in class Biorythm, where it is asking me to create a constructor, however I do not need one. But when I do crate one it gives the same error but in my parent class date which has a constructor.

Any help is appreciated!

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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//Option #1
//Question #1
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

#define PI 3.141593

class date {
			
public:

	//Date of birth
int m; //month
	int y; //year
		int d; //d ay
			int timeSinceBirth;

			int currentM;
			int currentY;
			int currentD;


	date(int x, int y,int z){
		d = x;
		m = y;
		y = z;

		currentM = 1;
		currentY = 2014;
		currentD = 14;
		
		timeSinceBirth= 0;
	}
	
	int daysInMonth(int month, int year){

		switch(month){
			case 1:
				return 31;
				break;
			case 2:
				if(isLeap(year)== true){
					return 29;
				    break;
				}
				else {
					return 28;
					break;
				}
			case 3:
				return 31;
				break;
			case 4:
				return 30;
				break;
			case 5:
				return 31;
				break;
			case 6:
				return 30;
				break;
			case 7:
				return 31;
				break;
			case 8:
				return 31;
				break;
			case 9:
				return 30;
				break;
			case 10:
				return 31;
				break;
			case 11:
				return 30;
				break;
			case 12:
				return 31;
				break;
			default:
				cout<<"Error in daysInMonth()"<<endl;
				return 0;
				break;

		}
	}

	bool isLeap(int year){
		if( year % 4 == 0 && year % 100 !=0 && year % 400 ==0 )
			return true;
		else
			return false;
	}

	void daysInRemainingMonth(){
		//How many days have passed from the current time in the current month
		if( daysInMonth(currentM,currentY) - currentD  >=0)
			timeSinceBirth +=  daysInMonth(currentM,currentY) - currentD;
	}
	
	void DaysLeft(){
		int once = 0;
		//calculating number of days since birth 
		while( y >= 0){
			for(int i =1; i <= 12; i++){
				//Condition to stop at the date of birth of the person

				//calculate time offset in the first month of birth
				if(once == 0){
					if( daysInMonth(m,y) - d  >=0)
						timeSinceBirth +=  daysInMonth(currentM,currentY) - currentD;
					once ++;
				}
				//Calculate  "normal days left"
				timeSinceBirth += daysInMonth(i,y);
			}

			y--;
		}
	}

	void calculate(){
		daysInRemainingMonth();
		DaysLeft();
	}
};

class Biorythm : public date {

public:

	//Necessary Empty Constructor
	Biorythm(){}

	int getPhysical(date x){

		x.calculate();

		int counter = timeSinceBirth;
		double answer = 0;

		while(counter >=23){
			answer = answer + sin(2*PI*timeSinceBirth/23);
			counter = counter - 23;
		}

		cout<<"The Physical Rythm of that person since birth is: "<< answer <<endl;
	}

	int getEmotional(date x){

		x.calculate();

		int counter = timeSinceBirth;
		double answer = 0;

		while(counter >=28){
			answer = answer + sin(2*PI*timeSinceBirth/28);
			counter = counter - 28;
		}


		cout<<"The Emotional Rythm of that person since birth is: "<< answer <<endl;
	}
	
	int getIntellectual(date x){
		x.calculate();

		int counter = timeSinceBirth;
		double answer = 0;

		while(counter >=33){
			answer = answer + sin(2*PI*timeSinceBirth/33);
			counter = counter - 33;
		}


		cout<<"The Intellectual Rythm of that person since birth is: "<< answer <<endl;
	}


};


int main(){


system("COLOR 2F");
	cout<<"Question #1"<<endl;
	int month = 0; 
	int day = 0;
	int year = 0;
	cout<<"Please Enter Your Date Of Birth (M/D/Y): "<<endl;
	cin>>month;
	cin>>day;
	cin>>year;

	date BR(day,month,year);
	Biorythm Rythm;

	cout<<Rythm.getPhysical(BR);
	cout<<Rythm.getEmotional(BR);
	cout<<Rythm.getIntellectual(BR);

	return 0;
}
You should post the error text verbatim. It's actually telling what the error is and where it is. You shouldn't expect us to compile your code.
When you supply a constructor such as date(int x, int y,int z) { // etc the compiler will not supply any default constructor.

If you intend to create a date object without any parameters, you need to specify a default constructor too such as: date() { } // default constructor though you may wish to add appropriate code to initialise the object with sensible default values.
You always need a constructor to be able to create a class object. If you do not define any constructor the compiler will automatically create a default constructor (if possible). A default constructor is a constructor that takes no arguments.

The automatically generated default constructor will call the default constructor of the base classes. In your case date is the base class but it doesn't have a default constructor so the generation of the default constructor for Biorythm will fail.

In your code you have tried to define the default Biorythm constructor yourself: Biorythm(){}
You have not specified what date constructor to use so it will assume you want to use the default date constructor, which doesn't exist.

What you can do is that you create a default constructor for the date class, or that you specify what date constructor to use like this: Biorythm() : date(1, 2, 3) {}
Topic archived. No new replies allowed.