【发布时间】:2013-12-14 13:55:00
【问题描述】:
In file included from /usr/local/Qt/linux-g++/include/QtCore/QLinkedList:2,
from /home/bamboo/Packages/Parser.h:17,
from /home/bamboo/Packages/Module.cpp:6:
/usr/local/Qt/linux-g++/include/QtCore/qlinkedlist.h: In member function 'void QLinkedList<T>::clear() [with T = int]':
/usr/local/Qt/linux-g++/include/QtCore/qlinkedlist.h:294: error: dereferencing pointer 'y' does break strict-aliasing rules
/usr/local/Qt/linux-g++/include/QtCore/qlinkedlist.h:293: note: initialized from here
/usr/local/Qt/linux-g++/include/QtCore/qlinkedlist.h:294: error: dereferencing pointer 'y' does break strict-aliasing rules
/usr/local/Qt/linux-g++/include/QtCore/qlinkedlist.h:293: note: initialized from here
在大行中,类Module 包含一个成员模板,例如:Parser<int>,并且定义了类解析器:
template <typename T> class Parser
{
// some stuff
QLinkedList<T> stuff;
};
并且这段代码可以很好地与gcc (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3 和g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 很好地编译并与g++ (Debian 4.4.5-8) 4.4.5 一起失败......我不知道为什么?任何人都看过这个错误信息并且任何人都知道这可能意味着什么?...更重要的是如何解决它?
【问题讨论】:
-
另外这篇文章确实很好地描述了它:cellperformance.beyond3d.com/articles/2006/06/…
-
是的,我在发布这个问题之前看到了那个帖子,并且 Qt 标头实际上正在使用该技术......所以这一定是不同的。
-
如果你创建一个sscce.org,你可能会得到更好的帮助,这样其他人就可以编译它并戳它。顺便说一句,什么 Qt 版本?
标签: c++ qt templates compiler-errors g++