mutable data members

Waldo Bastian bastian at kde.org
Wed Jan 22 11:32:54 GMT 2003


On Wednesday 22 January 2003 12:14, Cornelius Schumacher wrote:
> Is there a special reason why we don't use the "mutable" C++ keyword in
> KDE?

Dunno, this is what kclipboard.cpp has to say about it:

    virtual QByteArray encodedData( const char *format ) const
    {
        int index = m_formats.find( format );
        if ( index > -1 )
        {
            // grmbl, gcc (2.95.3 at least) doesn't let me call m_data.at(),
            // due to it being non-const. Even if mutable.
            QPtrList<QByteArray> *list =
                const_cast<QPtrList<QByteArray> *>( &m_data );
            return *(list->at( index ));
        }

        return QByteArray();
    }

private:
    mutable QStrList m_formats;
    QPtrList<QByteArray> m_data;
};

-- 
bastian at kde.org -=|[ SuSE, The Linux Desktop Experts ]|=- bastian at suse.com





More information about the kde-core-devel mailing list