【问题标题】:Why is compiling this code producing an error?为什么编译此代码会产生错误?
【发布时间】:2012-01-03 17:32:03
【问题描述】:

我相信这是正确的标题:

  #include <cstdio>

注意,上面的声明和这个有区别:

  #include <stdio.h>

第一个将所有内容放在“std”命名空间中,第二个没有。所以我用的是第一个。

下面是我在 aix6.1 上使用 g++4.4.6 编译的代码:-

#include <cstdarg> //< va_list
#include <cstdio>  //< vsnprintf()
#include "virtual_utils.h"

namespace VS
{


const char* format_str( const char* str, ... ) throw()
{
  static char buf[10][1024];
  static unsigned long buf_no = 0;

  char* cur_buf = buf[ ++buf_no % 10 ];
  buf_no %= 10;

  va_list vl;
  va_start( vl, str );
#ifdef _MSC_VER
  std::_vsnprintf( cur_buf, sizeof(buf), str, vl );
#else
  std::vsnprintf( cur_buf, sizeof(buf), str, vl );
#endif

  return cur_buf;
}


} //< namespace VS

这些是我得到的以下错误:-

virtual_utils.C: In function 'const char* VS::format_str(const char*, ...)':
virtual_utils.C:28: error: 'vsnprintf' is not a member of 'std'

编辑: 修改上述代码以删除#include "virtual_utils.h" 并添加main()compiles with a warning under gcc4.3.4 on Ideonecleanly under gcc4.5.1

【问题讨论】:

标签: c++ gcc aix


【解决方案1】:

使用--save-temps 编译,并检查它生成的.ii 文件。这应该清楚地说明什么是在什么命名空间中定义的,什么不是。

【讨论】:

  • 已知错误 -- “virtual_utils.C:28: error: 'vsnprintf' is not a member of 'std'”。
  • 错误已知,原因未知,解决方法未知。这将向您展示编译器看到的内容,您可以从中学习如何处理它。
  • 我们知道 vsnprintf 不是 std 的成员。它可以用 gcc-4.0.2/aix 编译吗?我们现在能做什么?
  • This 建议 cstdio 不应定义 vnsprintf。 GCC 4.0.2 可能已损坏并已修复,尽管我没有方便的标准来确认这一点。您可以使用 stdio.h,也可以用不同的方式编写代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-18
  • 1970-01-01
  • 2023-03-22
相关资源
最近更新 更多