Solved

C++ warning: cannot pass objects of non-POD type

Posted on 2012-03-19
5
558 Views
Last Modified: 2012-03-20
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;
0
Comment
Question by:1240
  • 2
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 37739836
What type does 'm_pPrefix' have? If that is not a 'char*' or any other POD type, this would cause the error, since you can't pass these to 'printf()'.
0
 

Author Closing Comment

by:1240
ID: 37740521
Thanks for the help, this was a good solution.
0
 
LVL 86

Expert Comment

by:jkr
ID: 37740522
I *am* curious, what type was it of?
0
 
LVL 30

Expert Comment

by:Axter
ID: 37743771
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.
0
 

Author Comment

by:1240
ID: 37744939
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now