From 00ded554233e70a1a57c5eba385d0d9415020627 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 7 Oct 1999 16:02:11 +0000 Subject: [PATCH] item about Borland C++ dislike for objects in ternary operator added git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3871 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/html/standard.htm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/html/standard.htm b/docs/html/standard.htm index 61d507667e..8cb5aab68b 100644 --- a/docs/html/standard.htm +++ b/docs/html/standard.htm @@ -50,6 +50,7 @@ C++ portability guide by David Williams.
  • Don't use STL
  • Don't declare variables inside for()
  • Don't use nested classes
  • +
  • Use ternary operator ?: carefully

  • General recommendations
  • @@ -332,6 +333,25 @@ you can try the following:

    A nice side effect is that you don't need to recompile all the files including the header if you change the PrivateLibClass declaration (it's an example of a more general interface/implementation separation idea). + +

  • Use ternary operator ?: carefully
  • + The ternary operator ?: shouldn't be used with objects (i.e. if any +of its operands are objects) because some compilers (notable Borland C++) fail +to compile such code. +

    Workaround: use if/else instead. +

    +    wxString s1, s2;
    +
    +    // Borland C++ won't compile the line below
    +    wxString s = s1.Len() < s2.Len() ? s1 : s2;
    +
    +    // but any C++ compiler will compile this
    +    wxString s;
    +    if ( s1.Len() < s2.Len() )
    +        s = s1;
    +    else
    +        s = s2;
    +

    -- 2.45.2