Inherit from std::runtime_error

Hello, everyone.

I am having difficulty inheriting from std::runtime_error.

All I have to do is construct an object with a message (I don't know why I cant just use std::runtime_error), and I am being forced to inherit from runtime_error.

Problem is, I really just don't know how. I either get linker errors or my compiler tells me "no default constructor available."

1
2
3
4
5
6
//Declaration in header file
          public:
          /**
          * @post Creates an exception with the message
          */
          MazeCreationException(const char* message);//I am forced to use this signature, and I cannot change it 


From here, I am unsure of where to go from here. I can't continue to work on my project until I get this to compile.

Any help anyone can give me would be greatly appreciated.

Thank you!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <stdexcept>

struct MazeCreationException : public virtual std::runtime_error
{
    using std::runtime_error::runtime_error ;
};

namespace gnu_microsoft_work_around
{
    struct MazeCreationException : public virtual std::runtime_error
    {
        MazeCreationException( const char* message ) : std::runtime_error(message) {}
    };
}

namespace legacy_cpp
{
    struct MazeCreationException : public virtual std::runtime_error
    {
        MazeCreationException( const char* message ) : std::runtime_error(message) {}
    };
}

int main()
{
    legacy_cpp::MazeCreationException bye( "bye" ) ;
    gnu_microsoft_work_around::MazeCreationException poor( "poor" ) ;
    
    MazeCreationException hello( "hello" ) ; // the GNU and microsoft libraries choke on this
}

http://coliru.stacked-crooked.com/a/0ca71563460371e9
http://rextester.com/PJKGG94174
Topic archived. No new replies allowed.