我有一个包含一些前向声明的头文件,但是当我在实现文件中包含头文件时,它会被包含在先前前向声明的包含之后,这会导致这样的错误。
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
解决这个问题的标准是什么?
提前致谢。
最佳答案
不要转发声明 std:ifstream - 只需导入 <iosfwd>
而是。
ifstream 是一个 typedef。
更多详情请看这里:http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.2/group__s27__2__iosfwd.html
关于C++前向声明问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2963356/