gpt4 book ai didi

c++ - Qt源代码是如何组织的

转载 作者:行者123 更新时间:2023-11-28 03:14:51 28 4
gpt4 key购买 nike

我正试图找到 QLinkedList::operator+( const QLinkedList<T> &list ) 的 Qt 实现,但我无法理解 Qt 源代码。这是 Qt 4.8.4 的一部分:

我在 .h 中找到了声明:

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

但是在 .cpp 中我看到的是这样的:

/*! \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+=()
*/

定义在哪里? Qt 使用什么组织?

最佳答案

如果不仔细看,实现似乎在 src/corelib/tools/qlinkedlist.h 中。 (您可以在此处查看此文件:http://qt.gitorious.org/qt/qt/blobs/4.8/src/corelib/tools/qlinkedlist.h)。

特别是,大多数函数都在文件顶部附近的一两行中定义(我链接的文件中的第 78 到 255 行)。它们使用一些更长的函数来完成工作(其中相当一部分无法通过公共(public) Qt API 访问),它们在我链接的文件的第 258 到 516 行定义。

因为 QLinkedList 是一个模板,所以将实现完全放在 header 中是有意义的(事实上,您“不能”[我不严格地使用该术语] 将实现放在 C++ 文件中)。有关其工作原理的更深入解释,请参阅以下问题:Why can templates only be implemented in the header file? .

你说的具体功能,QLinkedList::operator+(const QLinkedList<T> &list) , 在我链接的文件的第 511 行定义。

关于c++ - Qt源代码是如何组织的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17240766/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com