看板Programming
标 题另一个c++练习的疑问
发信站KKCITY (Sat Mar 1 15:00:15 2008)
转信站ptt!ctu-reader!ctu-gate!news.nctu!news.ntu!news.au!zoonews.ee.ntu!news
我在
double volume(const double length, const double breadth, const double
height) throw (...)
出现
12 C:\Documents and Settings\rong\桌面\新文件2.cpp expected identifier
before '...' token
错误讯息呢?
附上我的语法..因不知该怎麽修改这个错误,只得丢上网路询问,请大家协助了,谢谢
!
#include <iostream>
using namespace std;
class cbox
{
private:
double m_length1;
double m_breadth1;
double m_height1;
public :
double volume(const double length, const double breadth, const double
height) throw (...)
{
if (length < 0)
{
throw std::out_of_range(_T("length out of range"));
}
else if (breadth < 0)
{
throw std::out_of_range(_T("breadth out of range"));
}
else if (height < 0)
{
throw std::out_of_range(_T("height out of range"));
}
else
{
m_length1 = length;
m_breadth1 = breadth;
m_height1 = height;
return m_height1 * m_length1 * m_breadth1;
}
}
};
int main()
{
cbox box1;
cbox box2;
try
{
cout << "第一个箱子体积=" << box1.volume(10,50,60) << endl;
}
catch (std::exception& e)
{
std::cerr << "Caught: " << e.what() << endl;
}
try
{
cout << "第二个箱子体积=" << box2.volume(10,-10,20) << endl;
//虽然资料有错 但是东西仍产生了 只是这是不良品
}
catch (std::exception& e)
{
std::cerr << "Caught: " << e.what() << endl;
}
cout <<endl;
return 0;
}
--
┌─────◆KKCITY◆─────┐ ◢
◤ ★ 线上音乐新震撼 ★ ◢
◤
│ bbs.kkcity.com.tw │ ^_^ / 随选随播免等待 KKBOX◤ ^_^ /
└──《From:140.109.123.38
》──┘ ◤ http://www.kkbox.com.tw ◤
--