这是我的程序,因为这个错误而失败:对'exception'的引用是不明确的.
这是为什么?
是因为我的类名是"异常"而C++已经有了使用名称"exeption"的其他功能吗?例如,在C++中,我们不能使用"int"作为变量.这个逻辑是否也适用于此?谢谢.
#include <iostream>
#include <math.h>
using namespace std;
class exception{
public:
exception(double x,double y ,double z)
{
cout<<"Please input a";
cin>>x;
cout<<"Please input b";
cin>>y;
cout<<"Please input c";
cin>>z;
a=x;
b=y;
c=z;
/*
try{
int sonsAge = 30;
int momsAge = 34;
if ( sonsAge > momsAge){
throw 99;
}
}
catch(int x)
{
cout<<”son cannot be older than mom, Error number :”<<x;
}
*/
try {
if (a==0) {
throw 0;
}
if ((b*b)-(4*a*c)<0) {
throw 1;
}
cout<<"x1 is"<<(-b+sqrt(b*b-4*a*c))/(2*a)<<endl
<<"x2 is"<<(-b-sqrt(b*b-4*a*c))/(2*a);
} catch (int x) {
if (x==0) {
cout<<"Error ! cannot divide by 0";
}
if (x==1) {
cout<<"The square root cannot be a negative number";
}
}
};
private:
double a,b,c;
};
int main()
{
exception ob1(3.2,12.3,412);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
std::exception是一个标准的类名; 它是标准异常层次结构的基本类型.您可以通过将其命名为自己的类来命名::exception.这是不使用的绝佳理由using namespace std.