Solved

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

Posted on 2012-03-19
5
542 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

707 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

12 Experts available now in Live!

Get 1:1 Help Now