CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

“超 级 警 告” 高手来帮忙!

楼主koeinova2002()2003-04-01 22:39:22 在 C/C++ / C语言 提问

自己写了一个类,都在头文件中,执行文件cpp中只#include   my.h   和   设了一个空main()  
   
  编译都通过,没有error。但却有106个warning!!真是奇了怪了!如下:  
   
  --------------------Configuration:   game   -   Win32   Debug--------------------  
  Compiling...  
  game.cpp  
  c:\program   files\microsoft   visual   studio\vc98\include\xtree(120)   :   warning   C4786:   'std::_Tree<std::basic_string<char,std::char_traits<char>,std::allocator<char>   >,std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char>   >   const   ,  
  enum   UserProfile::uLevel>,std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char>   >,enum   UserProfile::uLevel,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>   >   >,std::allocator<enum   UserProfile::uLevel  
  >   >::_Kfn,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char>   >   >,std::allocator<enum   UserProfile::uLevel>   >'   :   identifier   was   truncated   to   '255'   characters   in   the   debug   information  
   
  warning   内容大多大同小异,我只列举其一。以下是我在my.h中的脚本,请高手指点迷津!非常感谢!特急!!!  
   
  (大家可以拿去到自己的机器上用VC++6.0编译一下,看看会不会出现   "   -   0   error(s),   106   warning(s)   "   。)  
   
  /////////////////////////////////////////////////////////////////////////////  
  //  
  //         my.h  
  //  
  /////////////////////////////////////////////////////////////////////////////  
   
  #include   <iostream>  
  #include   <map>  
  #include   <string>  
   
  using   namespace   std;  
   
  class   UserProfile  
  {  
  public:  
  enum   uLevel   {Beginner,Intermediate,Advanced,   Guru};  
   
  //construcor   function  
  UserProfile(string   login,uLevel   =   Beginner);  
  UserProfile();  
   
  //overloaded   operators  
  bool   operator==(const   UserProfile&);  
  bool   operator!=(const   UserProfile   &rhs);  
   
  string   login()   const   {return   _login;}  
  string   user_name()   const   {return   _user_name;}  
  int   login_count()   const   {return   _times_logged;}  
  int   guess_count()   const   {return   _guesses;}  
  int   guess_correct()   const   {return   _correct_guesses;}  
  double   guess_average()   const;  
  string   level()   const;  
   
  void   reset_login(const   string   &val){_login   =   val;}  
  void   user_name(const   string   &val){_user_name   =   val;}  
   
  void   reset_level(const   string&);  
  void   reset_level(uLevel   newlevel){_user_level   =   newlevel;}  
   
  void   reset_login_count(int   val){_times_logged   =   val;}  
  void   reset_guess_count(int   val){_guesses   =   val;}  
  void   reset_guess_correct(int   val){_correct_guesses   =   val;}  
   
  void   bump_login_count(int   cnt=1){_times_logged   +=   cnt;}  
  void   bump_guess_count(int   cnt=1){_guesses   +=   cnt;}  
  void   bump_guess_correct(int   cnt=1){_correct_guesses   +=   cnt;}  
   
  private:  
  string   _login;  
  string   _user_name;  
  int   _times_logged;  
  int   _guesses;  
  int   _correct_guesses;  
  uLevel   _user_level;  
   
  static   map<string,uLevel>   _level_map;  
  static   void   init_level_map();  
  static   string   guest_login();  
   
  };  
   
  inline   double   UserProfile::guess_average()   const  
  {  
  return   _guesses  
  ?   double(_correct_guesses)   /   double(_guesses)   *   100  
  :   0.0;  
  }  
   
  inline   UserProfile::UserProfile(string   login,uLevel   level)  
  :   _login(login),_user_level(level),  
  _times_logged(1),_guesses(0),_correct_guesses(0){}  
   
  #include   <cstdlib>  
   
   
  inline   UserProfile::UserProfile()  
  :   _login("guest"),_user_level(Beginner),  
  _times_logged(1),_guesses(0),_correct_guesses(0)  
  {  
  static   int   id   =   0;  
  char   buffer[16];  
  _itoa(id++,buffer,10);  
  _login   +=   buffer;  
  }  
   
  inline   bool   UserProfile::  
  operator==(const   UserProfile   &rhs)  
  {  
  if   (_login   ==   rhs._login   &&  
  _user_name   ==   rhs._user_name)  
  return   true;  
  return   false;  
  }  
   
  inline   bool   UserProfile::  
  operator   !=   (const   UserProfile   &rhs){return   !   (*this   ==   rhs);}  
   
   
  inline   string   UserProfile::level()   const  
  {  
  static   string   _level_table[]={  
  "Beginner","Intermediate","Advanced",   "Guru"  
  };  
  return   _level_table[_user_level];  
  }  
   
  ostream&   operator<<(ostream   &os,   const   UserProfile   &rhs)  
  {  
  os     <<     "\t登录姓名:"   <<   "   \t   "   <<   rhs.login()   <<   "   \n\n     "  
  <<     "\t级         别:"   <<   "   \t   "   <<   rhs.level()   <<   "   \n\n     "  
  <<     "\t登录次数:"   <<   "   \t   "   <<   rhs.login_count()   <<   "   \n\n       "  
  <<     "\t猜数次数:"   <<   "   \t   "   <<   rhs.guess_count()   <<   "   \n\n     "  
  <<     "\t猜中次数:"   <<   "   \t   "   <<   rhs.guess_correct()   <<   "   \n\n     "  
  <<     "\t猜中百分率:"   <<   "   \t   "   <<   rhs.guess_average()   <<   "%"    
  <<endl;  
  return   os;  
  }  
   
  map<string,UserProfile::uLevel>   UserProfile::_level_map;  
   
  void   UserProfile::init_level_map()  
  {  
  _level_map["Beginner"]   =   Beginner;  
  _level_map["Intermediate"]   =   Intermediate;  
  _level_map["Advanced"]   =   Advanced;  
  _level_map["Guru"]   =   Guru;  
  }  
   
   
   
  inline   void   UserProfile::reset_level(const   string   &level)  
  {  
  map<string,uLevel>::iterator   it;  
  if   (_level_map.empty())  
  init_level_map();  
   
  _user_level   =    
  ((it   =   _level_map.find(level))   !=   _level_map.end())  
  ?   it->second   :   Beginner;  
  }  
   
   
   
  istream&   operator>>(istream   &is,UserProfile   &rhs)  
  {  
  string   login,level;  
  is   >>   login   >>   level;  
   
  int   lcount,   gcount,   gcorrect;  
  is   >>   lcount   >>   gcount   >>   gcorrect;  
  rhs.reset_login(login);  
  rhs.reset_level(level);  
   
  rhs.reset_guess_count(lcount);  
  rhs.reset_guess_count(gcount);  
  rhs.reset_guess_correct(gcorrect);  
   
  return   is;  
  }  
   
  问题点数:100、回复次数:3Top

1 楼kicool(多米诺)回复于 2003-04-01 22:49:43 得分 50

这是因为由于使用模板,你的类型字符大于255.Top

2 楼kicool(多米诺)回复于 2003-04-01 22:53:49 得分 0

把这条预编译指令加在合适的地方  
  #pragma   warning   (disable   :   4786)  
  你要是用到了标准库,几乎一定会产生这个警告  
   
  Top

3 楼micropentium6(小笨|曾经的美好)回复于 2003-04-01 23:08:27 得分 50

#pragma   warning   (disable   :   4786)  
  放在#include   <map>上一行就可以了Top

相关问题

  • RichEdit的Bug警告(级别:中级)
  • 警告!
  • 警告!
  • 警告大家,千万不要使用 超级兔子魔法设置 这个软件,蔡旋在里面设置了破坏系统的功能!!
  • 特级警告:本拉登被击毙了!!!
  • 请问/W4警告级别怎么设置?
  • Tc:警告
  • JSP警告
  • 警告-----------------newyj------------
  • 警告:helpeachother

关键词

  • 编译
  • userprofile
  • guess
  • level
  • ulevel
  • rhs
  • login
  • beginner
  • reset
  • gcount

得分解答快速导航

  • 帖主:koeinova2002
  • kicool
  • micropentium6

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo