Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2012-03-19
5
Medium Priority
?
634 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

610 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