Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ assignment question 7 199
PDF library for Delphi 2 121
getting a fire fox page (view page source ) in c++ 6 42
How to copy an image file into clipboard C/C++? 1 168
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

776 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