나는 이것에 대해 많은 질문이 있지만 나는 그것을 얻지 못한다는 것을 알고있다. D : 미안하지만, 나는 이것에 대해 새롭다. 이해하지 못합니다 ... 이것은 숙제입니다. 타이머 알람을 설정해야하는데, 갑자기이 오류가 나타났습니다. (학교 컴퓨터에서 일할 때 갑자기 나타났습니다.) 나는 어떻게 수정해야할지 모르겠다. 나 좀 도와 줘!C++ 오류 c2512 : 기본 생성자를 사용할 수 없음
#include "stdafx.h"
#include <iostream>
using namespace std;
class Display {
public:
Display(int lim);
void Increment();
void SetValue(int val);
int GetValue();
void Show();
int GetLimit();
private:
int limit, value;
};
class Timer {
public:
Timer();
void Increment();
void Set();
void SetAlarm();
void Show();
void ShowAlarm();
private:
Display hours, minutes, seconds, alarmH, alarmM, alarmS;
};
Display::Display(int lim) {
value=0;
limit=lim; }
void Display::Increment() {
value++;
if (value==limit)
value=0; }
void Display::SetValue(int val) {
if (val<0)
val=-val;
value=(val%limit); }
int Display::GetValue() {
return value; }
void Display::Show() {
if (value<10)
cout<<"0";
cout<<value; }
int Display::GetLimit() {
return limit; }
Timer::Timer():hours(24), minutes(60), seconds(60) {
}
void Timer::Increment() {
seconds.Increment();
if(seconds.GetValue()==0) {
minutes.Increment();
if(minutes.GetValue()==0)
hours.Increment();} }
void Timer::Show() {
hours.Show();
cout<<':';
minutes.Show();
cout<<':';
seconds.Show(); }
void Timer::ShowAlarm() {
alarmH.Show();
cout<<':';
alarmM.Show();
cout<<':';
alarmS.Show(); }
void Timer::Set() {
int setting;
cout<<"Poner horas a que valor?\n";
cout<<"Ingresa un entero entre 0 y "; cout<<hours.GetLimit()<<": ";
cin>>setting;
hours.SetValue(setting);
cout<<"Poner minutos a que valor?\n";
cout<<"Ingresa un entero entre 0 y "; cout<<minutes.GetLimit()<<": ";
cin>>setting;
minutes.SetValue(setting);
cout<<"Poner segundos a que valor?\n";
cout<<"Ingresa un entero entre 0 y "; cout<<seconds.GetLimit()<<": ";
cin>>setting;
seconds.SetValue(setting); }
void Timer::SetAlarm() {
int setting;
cout<<"Poner horas a que valor?\n";
cout<<"Ingresa un entero entre 0 y "; cout<<hours.GetLimit()<<": ";
cin>>setting;
alarmH.SetValue(setting);
cout<<"Poner minutos a que valor?\n";
cout<<"Ingresa un entero entre 0 y "; cout<<minutes.GetLimit()<<": ";
cin>>setting;
alarmM.SetValue(setting);
cout<<"Poner segundos a que valor?\n";
cout<<"Ingresa un entero entre 0 y "; cout<<seconds.GetLimit()<<": ";
cin>>setting;
alarmS.SetValue(setting); }
void main() {
Timer t;
cout<<"Aqui esta el valor incial del timer: ";
t.Show();
cout<<"\n\n";
t.Set();
cout<<"Aqui estan los nuevos valores: ";
t.Show();
cout<<"\n\n";
cout<<"Lo corremos por 10 segundos...\n";
for (int i=0;i<=10;i++) {
t.Increment();
t.Show();
cout<<'\n'; }
}
당신의 오류 가능성이 오류 라인을 가리켜 야합니다 고려하고있는 명확 할 수 없습니다. – Rapptz
힌트 : 'Display'클래스의 멤버가 있지만 'Display'에는 기본 생성자가 없습니다. – Rapptz
네, 그렇습니다 만, 그건 의미가 없습니다 ... 그것은 61 행에 있습니다. Timer :: Timer() : 시간 (24), 분 (60), 초 (60) { } 하지만 Display에는 기본 생성자가 없습니다 ... – Opponent019