相关疑难解决方法(0)

关于在默认析构函数中丢失throw说明符的c ++标准所说的内容

三个不同的编译器显示编译此代码的三种不同行为:

class MyException : public std::exception
{
 public:
  MyException(std::string str) : m_str(str) {}
  virtual const char * what() const throw () {return m_str.c_str(); }
 protected:
  std::string m_str;
};
Run Code Online (Sandbox Code Playgroud)

Sun C++ 5.8 Patch 121017-22 2010/09/29:警告函数MyException :: 〜MyException ()只能抛出函数std :: exception :: ~exception()抛出的异常它会覆盖

g ++ 3.4.3: `virtual MyException:~MyException()'的错误抛出说明符

Visual Studio 2005:非常高兴(既不是错误也不是警告)

class exception {
public:
  exception () throw();
  exception (const exception&) throw();
  exception& operator= (const exception&) throw();
  virtual ~exception() throw();
  virtual const char* what() const throw(); …
Run Code Online (Sandbox Code Playgroud)

c++ visual-c++

19
推荐指数
2
解决办法
7853
查看次数

C++中的松散抛出说明符错误

以下代码生成"Looser throw specifier error".你能帮我解决这个错误吗?

class base
{
    virtual void abc() throw (exp1);
}

void base::abc() throw (exp1)
{
    ......
}

class sub : public base
{
    void abc() throw(exp1, exp2);
}

void sub::abc() throw (exp1, exp2)
{
    .....
}
Run Code Online (Sandbox Code Playgroud)

c++ exception

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×2

exception ×1

visual-c++ ×1