S
slack_justyb
Hello everyone,
Recently I was coding a little app at home on my Linux box. I'm
using gcc 3.3.4 (well actually g++) to compile my programs. I was
compiling a module of the app into object code and got a nasty error
that gcc could not find a matching constructor. Here is the offening
code in simplified terms.
---code----
//file: myexception.hh
#include <exception>
#include <string>
using namespace std;
class MyException : public exception {
public:
MyException(const string & Message = "") :
exception(Message.c_str()) {}
};
//End of file.
---code---
And simply put this is what I would like to do with it.
---code---
#include <iostream>
#include <myexception.hh>
//And whatever other headers I may use.
void blah() { throw MyException("Blah, not done yet!"); }
int main() {
//Some code here...
try {
blah()
}
catch (MyException e) {
cout << e.what() << endl;
}
//and so on...
}
This seems to work with the HP-UX compiler and seems to be valid
code in most of the books I have read, however, upon inspection of the
header file on Linux, it does indeed lack a constructor for
std::exception::exception(const char *)
However, the GNU header seems to have a public function member
called what(). This leads me to believe that somewhere it has a
private data member that holds a message of some sort.
This leads me to my question: If the GNU c++ library lacks a
constructor to set a data member to hold some sort of message, then how
does one set a message at all.
Thank you all in advance,
Justin
Recently I was coding a little app at home on my Linux box. I'm
using gcc 3.3.4 (well actually g++) to compile my programs. I was
compiling a module of the app into object code and got a nasty error
that gcc could not find a matching constructor. Here is the offening
code in simplified terms.
---code----
//file: myexception.hh
#include <exception>
#include <string>
using namespace std;
class MyException : public exception {
public:
MyException(const string & Message = "") :
exception(Message.c_str()) {}
};
//End of file.
---code---
And simply put this is what I would like to do with it.
---code---
#include <iostream>
#include <myexception.hh>
//And whatever other headers I may use.
void blah() { throw MyException("Blah, not done yet!"); }
int main() {
//Some code here...
try {
blah()
}
catch (MyException e) {
cout << e.what() << endl;
}
//and so on...
}
This seems to work with the HP-UX compiler and seems to be valid
code in most of the books I have read, however, upon inspection of the
header file on Linux, it does indeed lack a constructor for
std::exception::exception(const char *)
However, the GNU header seems to have a public function member
called what(). This leads me to believe that somewhere it has a
private data member that holds a message of some sort.
This leads me to my question: If the GNU c++ library lacks a
constructor to set a data member to hold some sort of message, then how
does one set a message at all.
Thank you all in advance,
Justin