错误:ISO C++ 不允许声明无类型的‘ContactsItem’ 错误:expected ‘;’ before ‘*’ token

来源:互联网 发布:hdfs如何保证数据可靠 编辑:程序博客网 时间:2024/06/06 17:02

刚刚遇到个问题,貌似不是第一次遇到了,在这里记录一下。

编译错误提示:

GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/lib64/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/QtCore -I/usr/include/QtNetwork -I/usr/include/QtGui -I/usr/include/QtXml -I/usr/include -I. -I. -I. -o ContactsItem.o ContactsItem.cpp

In file included from ContactsItem.h:6,
                 from ContactsItem.cpp:1:
GroupItem.h:50: 错误:ISO C++ 不允许声明无类型的‘ContactsItem’
GroupItem.h:50: 错误:expected ‘;’ before ‘*’ token
make: *** [ContactsItem.o] 错误 1


我这里的问题是我在ContactsItem类的头文件ContactsItem.h中包含了GroupItem.h,而GroupItem.h中又包含了ContactsItem.h头文件, 并声明有ContactsItem的对象。

所以在编译到ContactsItem.o时报ContactsItem类型没定义,因为GroupItem.h中声明有ContactsItem对象,而在ContactsItem.h包含GroupItem.h时还没有定义类ContactsItem。

所以编译到ContactsItem时就报错了。


0 0
原创粉丝点击