cannot pass objects of non-POD type
移植代碼到Linux下,運(yùn)行總是崩潰(在windows下正常)。
調(diào)試發(fā)現(xiàn)問(wèn)題出在下列語(yǔ)句:
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|
提示在運(yùn)行時(shí)會(huì)異常。
查找 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、不要忽視編譯時(shí)的任何一個(gè) Warning .2、正確使用輸入輸出流,避開(kāi)高危函數(shù)。
1、printf("Hello %s" ,str.c_str());
2、cout<<str;
string 非原生類型 non-POD,編譯器無(wú)法把它傳入.
下面是一個(gè)網(wǎng)上的小例子。
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
1、不要忽視編譯時(shí)的任何一個(gè) Warning .2、正確使用輸入輸出流,避開(kāi)高危函數(shù)。
1、printf("Hello %s" ,str.c_str());
2、cout<<str;
string 非原生類型 non-POD,編譯器無(wú)法把它傳入.
下面是一個(gè)網(wǎng)上的小例子。
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 多彩人生 閱讀(1256) 評(píng)論(0) 編輯 收藏 引用