“超 级 警 告” 高手来帮忙!
自己写了一个类,都在头文件中,执行文件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




