移植代码到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() );
本文解决了在将代码从Windows移植到Linux时遇到的wxString使用wxString::Format导致的程序崩溃问题。通过更改字符串处理方式,实现了跨平台兼容。
3628

被折叠的 条评论
为什么被折叠?



