C++前向声明问题

标签 c++ forward-declaration

我有一个包含一些前向声明的头文件,但是当我在实现文件中包含头文件时,它会被包含在先前前向声明的包含之后,这会导致这样的错误。

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/

相关文章:

c++ - 三角形类 C++

c++ - 移动到容器中的迭代器

c++ - 如何在 std::list 中使用递归?

c++ - 模板运算符返回对抽象类的引用

c++ - 为什么概念 c++ 中没有前向声明?

c++ - 为什么这段代码不起作用?我收到错误 : incomplete type or does not name a type

c++ - 类 Bar *bar 之类的指针的名称是什么

c++ - 即使在二进制模式下,C++ 中的 0x0A 字符也会出现问题。 (将其解释为新文件)

c++ - 结构前向声明错误 : Typedef redefinition with different types

c++ - C++ 中缺少前向声明的问题