实例代码:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Time {
private:
void initMillTime(int mls) {
Millisecond = mls;
}
int Millisecond;
public:
int Hour;
int Minute;
int Second = {0};
mutable int testVal;
const int ctestvalue;
Time(int temphour, int tmpmin, int tmpsec) :ctestvalue(80){
Hour = temphour;
Minute = tmpmin;
Second = tmpsec;
initMillTime(0);
cout << "调用了构造函数Time(int temphour, int tmpmin, int tmpsec)" << endl;
}
Time() :ctestvalue(80) {
Hour = 12;
Minute = 59;
Second = 59;
initMillTime(50);
cout << "调用了构造函数Time()" << endl;
}
void addHour(int tmphour) {
Hour += tmphour;
}
void addHour1(int tmphour) const{
}
void fixVal() const {
testVal = 10;
}
Time& add_hour(int tmphour) {
Hour += tmphour;
return *this;
}
static int s_val;
};
int Time::s_val = 10;
class Time2{
public:
Time2(int){};
Time2() = default;
public:
int Hour;
int Minute;
int Second{ 0 };
};
int main() {
Time2 myTime2;
system("pause");
return 0;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-61844.html