type 'int' unexpected这个错误怎么改才是对的
#include<iostream>usingnamespacestd;classTime{pubilc:inthour;intminute;intsec;};Timet...
# include <iostream>
using namespace std;
class Time
{pubilc:
int hour;
int minute;
int sec;
};
Time t;
void set_time(void) //定义set.time函数
{
cin >> t.hour;
cin >> t.minute;
cin >> t.sec;
}
void show_time(void)
{
cout << t.hour << ":" << t.minute << ":" << t.sec << endl;
}
int main ()
{
set_time();
show_time();
return 0
}
Compiling...
exam-1.cpp
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(6) : error C2062: type 'int' unexpected
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(6) : error C2238: unexpected token(s) preceding ';'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(13) : error C2039: 'hour' : is not a member of 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(5) : see declaration of 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(14) : error C2248: 'minute' : cannot access private member declared in class 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(7) : see declaration of 'minute'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(15) : error C2248: 'sec' : cannot access private member declared in class 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(8) : see declaration of 'sec'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(20) : error C2039: 'hour' : is not a member of 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(5) : see declaration of 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(20) : error C2248: 'minute' : cannot access private member declared in class 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(7) : see declaration of 'minute'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(20) : error C2248: 'sec' : cannot access private member declared in class 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(8) : see declaration of 'sec'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(29) : error C2143: syntax error : missing ';' before '}'
执行 cl.exe 时出错.
exam-1.obj - 1 error(s), 0 warning(s) 展开
using namespace std;
class Time
{pubilc:
int hour;
int minute;
int sec;
};
Time t;
void set_time(void) //定义set.time函数
{
cin >> t.hour;
cin >> t.minute;
cin >> t.sec;
}
void show_time(void)
{
cout << t.hour << ":" << t.minute << ":" << t.sec << endl;
}
int main ()
{
set_time();
show_time();
return 0
}
Compiling...
exam-1.cpp
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(6) : error C2062: type 'int' unexpected
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(6) : error C2238: unexpected token(s) preceding ';'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(13) : error C2039: 'hour' : is not a member of 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(5) : see declaration of 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(14) : error C2248: 'minute' : cannot access private member declared in class 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(7) : see declaration of 'minute'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(15) : error C2248: 'sec' : cannot access private member declared in class 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(8) : see declaration of 'sec'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(20) : error C2039: 'hour' : is not a member of 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(5) : see declaration of 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(20) : error C2248: 'minute' : cannot access private member declared in class 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(7) : see declaration of 'minute'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(20) : error C2248: 'sec' : cannot access private member declared in class 'Time'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(8) : see declaration of 'sec'
f:\a资料\c++primer练习\c++程序设计 谭浩强\类和对象\习题1\exam-1.cpp(29) : error C2143: syntax error : missing ';' before '}'
执行 cl.exe 时出错.
exam-1.obj - 1 error(s), 0 warning(s) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询