#include<iostream>
using namespace std;
class Time
{
private:
int hour;
int minute;
int sec;
public:
void set_time();
void show_time();
};
int main()
{
Time t;
t.set_time();
t.show_time();
return 0;
}
void Time::set_time()
{
cin>>t.hour;
cin>>t.minute;
cin>>t.sec;
}
void Time::show_time()
{
cout<<t.hour<<":"<<t.hour<<":<<"t.sec<<endl;
}
编译提示:
t1.cpp(23) : error C2065: 't' : undeclared identifier
t1.cpp(23) : error C2228: left of '.hour' must have class/struct/union type
t1.cpp(24) : error C2228: left of '.minute' must have class/struct/union type
t1.cpp(25) : error C2228: left of '.sec' must have class/struct/union type
t1.cpp(29) : error C2228: left of '.hour' must have class/struct/union type
t1.cpp(29) : error C2228: left of '.hour' must have class/struct/union type
t1.cpp(29) : error C2146: syntax error : missing ';' before identifier 't'
t1.cpp(29) : error C2228: left of '.sec' must have class/struct/union type
执行 cl.exe 时出错.