dimanche 24 janvier 2016

How to automate class declarations?

I have some exceptions derived from std::exception or std::runtime_error. The only method is constructor explicit MyExceptionX(const char *text = "") : std::exception(text) {}. Are there ways to make this code simpler without use of macro?

class MyException1: public std::exception
{
public:
    explicit MyException1(const char *text = "") : std::exception(text) {}
};

class MyException2: public std::exception
{
public:
    explicit MyException2(const char *text = "") : std::exception(text) {}
};

class MyException3: public std::exception
{
public:
    explicit MyException3(const char *text = "") : std::exception(text) {}
};

//...

Aucun commentaire:

Enregistrer un commentaire