From: Vadim Zeitlin Date: Sun, 20 Jan 2002 15:20:17 +0000 (+0000) Subject: tried to make wxArrayString(bool autosort) ctor more explicit, e.g. prevent it from... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/0fe1f685b4d05fefd042ebb4a88bb8789ed237c2 tried to make wxArrayString(bool autosort) ctor more explicit, e.g. prevent it from being used in implicit conversions from char * to wxArrayString git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13676 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/string.h b/include/wx/string.h index ee258c42b9..b5b8104dea 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -989,9 +989,17 @@ public: const wxString& second); // constructors and destructor - // default ctor: if autoSort is TRUE, the array is always sorted (in - // alphabetical order) - wxArrayString(bool autoSort = FALSE); + // default ctor + wxArrayString() { Init(FALSE); } + // if autoSort is TRUE, the array is always sorted (in alphabetical order) + // + // NB: the reason for using int and not bool is that like this we can avoid + // using this ctor for implicit conversions from "const char *" (which + // we'd like to be implicitly converted to wxString instead!) + // + // of course, using explicit would be even better - if all compilers + // supported it... + wxArrayString(int autoSort) { Init(autoSort != 0); } // copy ctor wxArrayString(const wxArrayString& array); // assignment operator @@ -1065,6 +1073,7 @@ public: bool operator!=(const wxArrayString& a) const { return !(*this == a); } protected: + void Init(bool autoSort); // common part of all ctors void Copy(const wxArrayString& src); // copies the contents of another array private: diff --git a/src/common/string.cpp b/src/common/string.cpp index 6bc1683a23..d0297f3c97 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -1904,7 +1904,7 @@ wxString& wxString::replace(size_t nStart, size_t nLen, #define STRING(p) ((wxString *)(&(p))) // ctor -wxArrayString::wxArrayString(bool autoSort) +void wxArrayString::Init(bool autoSort) { m_nSize = m_nCount = 0; @@ -1915,10 +1915,7 @@ wxArrayString::wxArrayString(bool autoSort) // copy ctor wxArrayString::wxArrayString(const wxArrayString& src) { - m_nSize = - m_nCount = 0; - m_pItems = (wxChar **) NULL; - m_autoSort = src.m_autoSort; + Init(src.m_autoSort); *this = src; }