c – 为什么编译此代码会产生错误?

c – 为什么编译此代码会产生错误?,第1张

概述我相信这是正确的标题: #include <cstdio> 请注意,上述声明与此声明之间存在差异: #include <stdio.h> 第一个将所有内容放在“std”命名空间中,第二个放在“std”命名空间中.所以我使用第一个. 下面是我在aix6.1上使用g 4.4.6编译代码: – #include <cstdarg> //< va_list#include <cstdio> //< 我相信这是正确的标题:

#include <cstdio>

请注意,上述声明与此声明之间存在差异:

#include <stdio.h>

第一个将所有内容放在“std”命名空间中,第二个放在“std”命名空间中.所以我使用第一个.

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

#include <cstdarg> //< va_List#include <cstdio>  //< vsnprintf()#include "virtual_utils.h"@R_403_6889@space 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,vl );#endif  return cur_buf;}} //< @R_403_6889@space 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 Ideone和cleanly under gcc4.5.1.

解决方法 使用–save-temps编译,并检查它生成的.ii文件.这应该清楚说明在什么命名空间中定义了什么,什么不是. 总结

以上是内存溢出为你收集整理的c – 为什么编译此代码会产生错误?全部内容,希望文章能够帮你解决c – 为什么编译此代码会产生错误?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/1225690.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-05
下一篇2022-06-05

发表评论

登录后才能评论

评论列表(0条)

    保存