Solved

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

Posted on 2012-03-19
5
596 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

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…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

696 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