【问题标题】:Incomplete type is not allowed: stringstream不允许不完整的类型:stringstream
【发布时间】:2011-08-12 12:02:33
【问题描述】:

为什么这行会报错Error: incomplete type is not allowed

stringstream ss;

【问题讨论】:

  • 你包含了哪些头文件?
  • 我猜有一个#include<stringstream> 或者我应该使用的东西? #include #include #include #include #include #include #include #include

标签: c++ types stringstream


【解决方案1】:

#include <sstream> 并使用完全限定名称,即std::stringstream ss;

【讨论】:

  • 该错误可能是由于 stringstream 被定义为未定义的泛型类型。
  • 我认为 Visual Studio 有时允许在不包含文件的情况下使用 stringstream。也许这是错误的原因
【解决方案2】:

一些系统头文件提供了std::stringstream 的前向声明,但没有定义。这使其成为“不完整类型”。要解决这个问题,您需要包含 <sstream> 标头中提供的定义:

#include <sstream>

【讨论】:

    【解决方案3】:

    incomplete type 错误是当编译器遇到使用它知道是类型的标识符时,例如因为它已经看到它的前向声明(例如 class stringstream;),但它没有看到它的完整定义 (class stringstream { ... };)。

    这可能发生在您没有在自己的代码中使用但仅通过包含的头文件出现的类型 - 当您包含使用该类型的头文件,而不包含该类型所在的头文件时定义。标头本身不包含它需要的所有标头是不寻常的,但并非不可能。

    对于标准库中的内容,例如 stringstream 类,请使用该类或单个函数的语言标准或其他参考文档(例如 Unix man 页面、MSDN 库等)来弄清楚您需要#include 使用它以及在哪个命名空间中找到它(如果有)。您可能需要搜索出现类名的页面(例如man -k stringstream)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多