exception种构造函数没有参数,那what成员函数返回什么字符串
exception类构造函数没有参数,那what成员函数返回什么字符串
继承exception时,需要传给exception一个字符串,会与形参不匹配。
并且是不是不能用string?
我的代码如下:
#ifndef MYEXCEPTION_H
#define MYEXCEPTION_H
#include <exception>
#include <iostream>
#include <string>
using namespace std;
class MyException:public exception
{
public:
MyException(const char *):exception(const char * ){}; virtual ~MyException() throw (); //编译报错 expected primary -expression before const 这是为什么呢
protected:
private:
};
class OMarkError:public MyException
{
public:
OMarkError():MyException("mark shuold be between 0 and 100."){}
};
class EMarkError:public MyException
{
public:
EMarkError():MyException("grade shuold be between A and E."){}
};
class MonthError:public MyException
{
public:
MonthError():MyException("Month shuold be between 1 and 12."){}
};
class DayError:public MyException
{
public:
DayError():MyException("Day error."){}
};
class ScriptError:public MyException
{
public:
ScriptError():MyException("script exceed."){}
};
#endif // MYEXCEPTION_H
------解决方案--------------------
继承exception时,需要传给exception一个字符串,会与形参不匹配。
并且是不是不能用string?
我的代码如下:
#ifndef MYEXCEPTION_H
#define MYEXCEPTION_H
#include <exception>
#include <iostream>
#include <string>
using namespace std;
class MyException:public exception
{
public:
MyException(const char *):exception(const char * ){}; virtual ~MyException() throw (); //编译报错 expected primary -expression before const 这是为什么呢
protected:
private:
};
class OMarkError:public MyException
{
public:
OMarkError():MyException("mark shuold be between 0 and 100."){}
};
class EMarkError:public MyException
{
public:
EMarkError():MyException("grade shuold be between A and E."){}
};
class MonthError:public MyException
{
public:
MonthError():MyException("Month shuold be between 1 and 12."){}
};
class DayError:public MyException
{
public:
DayError():MyException("Day error."){}
};
class ScriptError:public MyException
{
public:
ScriptError():MyException("script exceed."){}
};
#endif // MYEXCEPTION_H
------解决方案--------------------
- C/C++ code
class MyException:public exception { public: MyException(const char *str):exception(str){} virtual ~MyException() throw (); //编译报错 expected primary -expression before const 这是为什么呢 protected: private: };