[code language=”cpp”]
#include <iostream>
using namespace std;
class time
{
public:
//定義建構元
time (int a,int b,double c){
hour=a;
minute=b;
second=c;
}
void show(void);
private:
int hour;
int minute;
double second;
};
void time::show(){
cout << hour << " : " << minute << " : " << second << endl;
}
int main(){
time t1(12,12,12); //呼叫建構元
t1.show();
}
[/code]
[code language=”cpp”]
#include <iostream>
using namespace std;
class time
{
public:
time (int,int,double); //建構元原型宣告
void show(void);
private:
int hour;
int minute;
double second;
};
//定義建構元
time::time (int a,int b,double c){
hour=a;
minute=b;
second=c;
}
void time::show(){
cout << hour << " : " << minute << " : " << second <<span style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" data-mce-type="bookmark" class="mce_SELRES_start"></span>< endl;
}
int main(){
time t1(12,12,12); //呼叫建構元
t1.show();
}
[/code]