0

I am trying to find the Qt implementation for QLinkedList::operator+( const QLinkedList<T> &list ), but I can't make sense of the Qt source code. This is part of Qt 4.8.4:

I found the declaration in the .h:

QLinkedList<T> operator+(const QLinkedList<T> &l) const;

But in the .cpp all I see is this:

/*! \fn QLinkedList<T> QLinkedList::operator+(const QLinkedList<T> &other) const

    Returns a list that contains all the items in this list followed
    by all the items in the \a other list.

    \sa operator+=()
*/

Where is the definition? What organization is Qt using?

Freedom_Ben
  • 11,247
  • 10
  • 69
  • 89

2 Answers2

2

Without looking too closely, the implementation seems to be in src/corelib/tools/qlinkedlist.h (you can view this file here: http://qt.gitorious.org/qt/qt/blobs/4.8/src/corelib/tools/qlinkedlist.h).

In particular, most of the functions are defined in one or two lines near the top of the file (lines 78 through 255 in the file I linked). These are using some longer functions to do the work (a fair portion of which are not accessible via the public Qt API), which are defined on lines 258 through 516 in the file I linked.

Beause QLinkedList is a template, it make sense for the implementation to be entirely in the header (in fact, you "can't" [I use the term loosely] put the implementation in a C++ file). For a more in-depth explanation of how this works, see this question: Why can templates only be implemented in the header file?.

The specific function you mention, QLinkedList::operator+(const QLinkedList<T> &list), is defined on line 511 of the file I linked.

Community
  • 1
  • 1
CmdrMoozy
  • 3,870
  • 3
  • 19
  • 31
0

The definition of QLinkedList<T>::operator+(const QLinkedList<T>& l) is also inside qlinkedlist.h at the bottom.

This is the definition:

template <typename T>
QLinkedList<T> QLinkedList<T>::operator+(const QLinkedList<T> &l) const
{
    QLinkedList<T> n = *this;
    n += l;
    return n;
}

Source: http://qt.gitorious.org/qt/qt/blobs/v4.8.4/src/corelib/tools/qlinkedlist.h

david
  • 623
  • 5
  • 13