1240
asked on
C++ warning: cannot pass objects of non-POD type
I know this is not uncommon error but in this case, do not see a problem. Can someone help identify the problem. The OS is CentOs 5 wit g++ 4.1.
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------
//Warning 1 on line 4 - warning: cannot pass objects of non-POD type ‘StdString<char, std::char_traits<char>, std::allocator<char> > ’ through ‘...’; call will abort at runtime
//Warning 2 on line 8 - warning: cannot pass objects of non-POD type ‘class stdStdString<char, std::char_traits<char>, std::allocator<char> >’ through ‘...’; call will abort at runtime
////////////////////////// ////////// ////////// /
1)try {
2) xxx.ParseFile(z_FileName.c _str());
3)}
// Warning 1 here
4)catch(ZZZ_Exception &except) {
5) printf("%s File error : %s\n", m_pPrefix, except.what());
6) return false;
7)}
// Warning 2 here
8)catch(...) {
9) printf("%s File error : Unknown Parse File Exception\n", m_pPrefix);
10) return false;
11)}
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- --
12)class ZZZ_Exception : public std::exception
13){
14) StdStringChar _what;
15) int m_nCode;
16)public:
17) ZZZ_Exception (const StdStringChar &what_arg, int nCode=0): _what (what_arg), m_nCode(nCode) {}
18) virtual const char *what () const throw() { return _what.c_str();}
19) virtual int code () const throw() { return(m_nCode);}
20) ~ZZZ_Exception() throw() {}
21)};
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
typedef StdString<char, std::char_traits<char>, std::allocator<char> > StdStringChar;
--------------------------
//Warning 1 on line 4 - warning: cannot pass objects of non-POD type ‘StdString<char, std::char_traits<char>, std::allocator<char> > ’ through ‘...’; call will abort at runtime
//Warning 2 on line 8 - warning: cannot pass objects of non-POD type ‘class stdStdString<char, std::char_traits<char>, std::allocator<char> >’ through ‘...’; call will abort at runtime
//////////////////////////
1)try {
2) xxx.ParseFile(z_FileName.c
3)}
// Warning 1 here
4)catch(ZZZ_Exception &except) {
5) printf("%s File error : %s\n", m_pPrefix, except.what());
6) return false;
7)}
// Warning 2 here
8)catch(...) {
9) printf("%s File error : Unknown Parse File Exception\n", m_pPrefix);
10) return false;
11)}
--------------------------
12)class ZZZ_Exception : public std::exception
13){
14) StdStringChar _what;
15) int m_nCode;
16)public:
17) ZZZ_Exception (const StdStringChar &what_arg, int nCode=0): _what (what_arg), m_nCode(nCode) {}
18) virtual const char *what () const throw() { return _what.c_str();}
19) virtual int code () const throw() { return(m_nCode);}
20) ~ZZZ_Exception() throw() {}
21)};
--------------------------
typedef StdString<char, std::char_traits<char>, std::allocator<char> > StdStringChar;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I *am* curious, what type was it of?
FYI:
If it's an std::string type, you can still use it with printf, but you have to pass it via .c_str().
Example:
printf("%s File error : %s\n", m_pPrefix.c_str(), except.what().c_str());
But (in general) it's could practice to use std::out with STL objects instead of printf.
If it's an std::string type, you can still use it with printf, but you have to pass it via .c_str().
Example:
printf("%s File error : %s\n", m_pPrefix.c_str(), except.what().c_str());
But (in general) it's could practice to use std::out with STL objects instead of printf.
ASKER
I added an access method and returned the c_str() from the method. Was looking in the Exception class for the problem and did see this issue. Thanks
ASKER