Slimelite BBS

Virtual Base Classes

Back to EMULATE

From Jonathan de Boyne Polla · 1996-04-02 07:19 · #73531 in EMULATE

dn>
  > Casting is such a low,
  > demeaning, kludgy 'C' sort of thing to have to do. :-)
dn>

  Really ?  How would you eliminate it in this example, then ?  (-:

    class Window {
        Window() ;
        ~Window() ;

        // ...

        const char * _get_text () const ;   // Actually these are SOM
        void _set_text ( const char * ) ;   // attribute accessors.

        // ...

    private:
        const char * actual_text ;
    }

    Window::Window () : actual_text(new char[1]) { actual_text[0] = 0 ; }

    Window::~Window () { delete[] actual_text ; }

    const char *
    Window::_get_text ( ) const
    {
        long len = WinQueryWindowTextLength(handle) ;
        delete[] actual_text ;
        const_cast<Window *>(this)->actual_text = new char[len + 1] ;
        if (actual_text) WinQueryWindowText(handle, len + 1, actual_text) ;
        return actual_text ;
    }

    void
    Window::_set_text ( const char * s )
    {
        delete[] actual_text ;
        actual_text = new char [ strlen(newtext) + 1 ] ;
        strcpy(actual_text, newtext) ;
        WinSetWindowText(handle, newtext) ;
    }

  Restriction :  you aren't allowed to cheat and use C++ features that
  no-one has implemented yet, such as `mutable'.  (-:

 > JdeBP <
___
 X MegaMail 2.10 #0:

--- Maximus/2 3.01
 * Origin: DoNoR/2,Woking UK (44-1483-725167)  (2:440/4)