本文介绍了C ++向前声明问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个头文件有一些转发声明,但是当我将头文件包含在实现文件中时,它包含在以前的转发声明的包含之后,会导致这样的错误。
I have a header file that has some forward declarations but when I include the header file in the implementation file it gets included after the includes for the previous forward declarations and this results in an error like this.
error: using typedef-name ‘std::ifstream’ after ‘class’
/usr/include/c++/4.2.1/iosfwd:145: error: ‘std::ifstream’ has a previous declaration.
class ifstream;
class A
{
ifstream *inStream;
}
// End of A.h
#include <ifstream>
using std::ifstream;
#include "A.h"
// etc
提前感谢。
推荐答案
不要转发declare std:ifstream - 改为只导入< iosfwd>
。
ifstream是一个typedef。
ifstream is a typedef.
详情请参阅:
See here for further details: http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.2/group_s27_2__iosfwd.html
这篇关于C ++向前声明问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!