colorful

zc qq:1337220912

 

cannot pass objects of non-POD type

移植代码到Linux下,运行总是崩溃(在windows下正常)。
调试发现问题出在下列语句:
   wxString szSiteHead = wxString::Format( wxT("<Location /%s>"), file.GetName() );
查看编译记录有下列警告信息
   warning: cannot pass objects of non-POD type 'class wxString' through '...'; call will abort at runtime|
提示在运行时会异常。
 
查找 POD type定义如下:非原生类型
 
POD stands for Plain Old Data - that is, a struct (or class) with no members except data members. Wikipedia goes into a bit more detail and defines a POD in C++ as "A Plain Old Data Structure in C++ is an aggregate class that contains only PODS as members, has no user-defined destructor, no user-defined copy assignment operator, and no nonstatic members of pointer-to-member type."
 
代码更改后OK。
wxString szSiteHead = wxString::Format( wxT("<Location /%s>"), file.GetName().c_str() );

===================================================================================
ctags: c++ warning "cannot pass objects of non-POD type"

1、不要忽视编译时的任何一个 Warning .2、正确使用输入输出流,避开高危函数。

1、printf("Hello %s" ,str.c_str());
2、cout<<str;

string 非原生类型 non-POD,编译器无法把它传入.

下面是一个网上的小例子。

im trying to compile following code
--------------------sam.cpp---------------------
#include <string>
#include <iostream>
#include <stdarg.h>
using namespace std;

void Write( const char* msg, const char* msg2, ...)
{
cout <<msg <<" "<<msg2<<endl;
}

int main()
{
string str("World");
Write("Hello","Debug out %s" ,str);
return 0;
}
-------------------------------------------

When i compile this code i get following compilation warning .

[oracle@sahyagiri test]$ g++ sam.cpp
sam.cpp: In function `int main()':
sam.cpp:17: warning: cannot pass objects of non-POD
type `struct std::string'
through `...'; call will abort at runtime

When i run the executable, a.out it fails with Illegal
instruction eror

posted on 2012-07-26 12:45 多彩人生 阅读(1162) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜