我用Dev C ++开发了具有getter和setter以及构造函数的C ++应用程序。我通过构造函数发送日,小时,分钟,秒变量,并希望将其打印出来。
但是在运行和编译时出现错误,例如“未编译源文件”。
如何解决此问题?我已经删除了collect2.exe文件,但问题仍然存在。
Sinif.CPP
#include "Sinif.h"
#include <iostream>
#include <iomanip>
using namespace std;
Sinif::Sinif(int d,int h, int m, int s) {
day=d;
hour = h;
minute = m;
second = s;
}
int Sinif::getDay() const {
return day;
}
void Sinif::setDay(int d) {
day = d;
}
int Sinif::getHour() const {
return hour;
}
void Sinif::setHour(int h) {
hour = h;
}
int Sinif::getMinute() const {
return minute;
}
void Sinif::setMinute(int m) {
minute = m;
}
int Sinif::getSecond() const {
return second;
}
void Sinif::setSecond(int s) {
second = s;
}
void Time::setTime(int d,int h, int m, int s) {
day=d;
hour = h;
minute = m;
second = s;
}
void Time::print() const {
cout << setfill('0');
cout << setw(2) << day
cout <<":"<< setw(2) << hour
<< ":" << setw(2) << minute
<< ":" << setw(2) << second << endl;
}
Sinif.h
#ifndef TIME_H
#define TIME_H
class Sinif {
private:
int day;
int hour;
int minute;
int second;
public:
Sinif(int d=0,int h = 0, int m = 0, int s = 0);
int getDay() const; // public getter for private data member hour
void setDay(int d);
int getHour() const; // public getter for private data member hour
void setHour(int h); // public setter for private data member hour
int getMinute() const; // public getter for private data member minute
void setMinute(int m); // public setter for private data member minute
int getSecond() const; // public getter for private data member second
void setSecond(int s); // public setter for private data member second
void setTime(int d,int h, int m, int s); // set hour, minute and second
void print() const; // Print a description of this instance in "hh:mm:ss"
}; // need to terminate the class declaration with a semicolon
#endif // end of "#ifndef" block
主CPP
#include <iostream>
#include "Sinif.h"
using namespace std;
int main() {
Sinif t1(25,23, 59, 59); // Test constructor
// Test all public member functions
t1.print();
t1.setDay(17);
t1.setHour(12);
t1.setMinute(30);
t1.setSecond(15);
t1.print(); // 12:30:15
cout << "Day is " << t1.getDay() << endl;
cout << "Hour is " << t1.getHour() << endl;
cout << "Minute is " << t1.getMinute() << endl;
cout << "Second is " << t1.getSecond() << endl;
Sinif t2; // Test constructor with default values for hour, minute and second
t2.print(); // 00:00:00
t2.setTime(10,1, 2, 3);
t2.print(); // 01:02:03
Sinif t3(12); // Use default values for minute and second
t3.print(); // 12:00:00
}
答案 0 :(得分:2)
阅读完整的构建输出,它将告诉您哪里出了问题以及在哪里。
在这种情况下,这可能是由于以下原因造成的:
<div class="pdf-container ">
<div class="canvas-container">
{{#if pageIsRendering}}
<div class="loader">
{{loading-spinner isLoading="true"}}
</div>
{{/if}}
</div>
</div>
(您的课程称为void Time::setTime(int d,int h, int m, int s) {
day=d;
hour = h;
minute = m;
second = s;
}
,而不是Sinif
。)
…还有这个
Time
(无终止分号。)
修正了这些问题后,your program compiles and runs(看起来像预期的输出)。
删除GCC的一部分,例如cout << setw(2) << day
。您可能现在必须重新安装工具链。