Получение ошибки при получении класса из std :: exception - PullRequest
0 голосов
/ 25 декабря 2018

enter image description here Я получаю класс из std :: exception, но я получил ошибку Вот мой код

#include "stdafx.h"
#include <iostream>

using namespace std;

class exp1 : public std::exception {
public:
    exp1() noexcept = default;
    ~exp1() = default;
    virtual const char* what() const noexcept
    {
        return "This is an exception";
    }
};


int main()
{
    try{
        int i; 
        cin >> i;
        if(i == 0)throw exp1() ;
        else {cout << i << endl;}
       }
    catch(exp1 & ex){
        cout << ex.what() << endl; 
       }
return 0;
}

Мой код работает нормально, но когда я включаю noexcept конструктору

exp1() noexcept = default;

, тогда я получаю ошибки

'exp1::exp1(void) noexcept': attempting to reference a deleted function 

и

the declared exception specification is incompatible with the generated one 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...