Issues with wxString: wxMac and wxMSW 2.6.3
Michiel.Salters at tomtom.com
Michiel.Salters at tomtom.com
Tue Sep 5 05:37:31 PDT 2006
Anthony T. wrote:
> Hi,
>
> I'm having a problem using wxString. Consider the following:
>
> class AnyFrame : public wxFrame {
> wxString str_debug; // Private member
>
> public:
> AnyFrame();
> void doSomething();
> };
>
> AnyFrame::AnyFrame() : wxFrame(...), str_debug("") { } // Have also
> tried str_debug("empty")
>
> void doSomething() {
> str_debug = "Test";
> }
>
> A call to doSomething causes the program to crash under Mac and Windows
> (other OSes not tested).
> Both point to this line in wx/string.h
>
> // accessor to string data
> wxStringData* GetStringData() const { return (wxStringData*)m_pchData
> - 1; }
This is not the "STL-based" (C++ Standard Library) wxString
implementation,
right? It may be a good idea to use that instead, but just as a general
principle.
(Any compile that doesn't have std::wstring today should be dumped)
You never need to initialize an empty string with "", wx or otherwise.
Basically, the need for "" initialization is a legacy from char* times.
It should
not matter either.
I suspect that the real error is the this-> pointer, though.
You can't see it in the code shown, but it is there, and I'm willing to
bet it's
bad.
HTH,
Michiel Salters
More information about the wx-users
mailing list