第一个C++例子

 #include <iostream>
using namespace std; class Time
{
private:
int hour;
int minute;
int second;
public:
//Time() //无参够创函数
//{
// hour = 0; minute = 0; second = 0;
//}
//Time(int h, int m, int s) //带参构造函数
//{
// hour = h; minute = m; second = s;
//}
Time(int h = , int m = , int s = ) : hour(h), minute(m), second(s){} //带参数初始化表的构造函数
void Set(int h, int m, int s);
void Show();
}; void Time::Set(int h, int m, int s)
{
hour = h; minute = m; second = s;
}
void Time::Show()
{
cout << hour << ":" << minute << ":" << second << endl;
} int main()
{
Time t1;
t1.Show();
t1.Set(, , );
t1.Show(); Time t2(, , );
t2.Show(); return ;
}
上一篇:python 小白(无编程基础,无计算机基础)的开发之路 day1


下一篇:JS中常遇到的浏览器兼容问题和解决方法【转】