编译成功 链接出错。。求看看
#include<iostream>#include<string>
using namespace std;
class User
{
private:
static string id[20][1];
static string pw[20][1];
static char *_pw;
static int count;
public:
User(string name,string pass)
{
for(unsigned int i=0;i<pass.length();i++)
_pw[i]=(pass[i]+i+1)%256;//密码加密
id[0][0]=name;
pw[0][0]=_pw;
}
static void Adduser(string name,string pass)
{
for(unsigned int i=0;i<pass.length();i++)
_pw[i]=(pass[i]+i+1)%256;
id[count++][0]=name;
count--;
pw[count++][0]=_pw;
return;
}
static int login(string name,string pass)
{
for(unsigned int i=0;i<pass.length();i++)
_pw[i]=(pass[i]+i+1)%256;
pass=_pw;
for(int i=0;i<count;i++)
if(name==id[i][0]&&pass==pw[i][0])
return 1;
return -1;
}
};
string User::id[20][1];
string User::pw[20][1];
char User::*pw;
int User::count;
int main()
{
char name[20],pass[20];
User u1("LiWei","liwei99");
u1.Adduser("ChenHanfu","20090208");
User::Adduser("ZhanGaolin","199146");
cout<<"Input username:";
cin>>name;
cout<<"Input password:";
cin>>pass;
if(User::login(name,pass)>=0)
cout<<"Success login!"<<endl;
else
cout<<"login fail!"<<endl;
return 0;
}
palace.cpp
Linking...
D:\工具\MinGW\MinGWStudio\palace\Debug\palace.o: In function `ZSt3minIjERKT_S2_S2_':
D:\工具\MinGW\MinGWStudio\palace\palace.cpp:(.text$_ZN4User5loginESsSs[User::login(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x1f): undefined reference to `User::_pw'
D:\工具\MinGW\MinGWStudio\palace\palace.cpp:(.text$_ZN4User5loginESsSs[User::login(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x50): undefined reference to `User::_pw'
D:\工具\MinGW\MinGWStudio\palace\palace.cpp:(.text$_ZN4User7AdduserESsSs[User::Adduser(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x1f): undefined reference to `User::_pw'
D:\工具\MinGW\MinGWStudio\palace\palace.cpp:(.text$_ZN4User7AdduserESsSs[User::Adduser(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x78): undefined reference to `User::_pw'
D:\工具\MinGW\MinGWStudio\palace\palace.cpp:(.text$_ZN4UserC1ESsSs[User::User(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x1f): undefined reference to `User::_pw'
D:\工具\MinGW\MinGWStudio\palace\Debug\palace.o:D:\工具\MinGW\MinGWStudio\palace\palace.cpp:(.text$_ZN4UserC1ESsSs[User::User(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x63): more undefined references to `User::_pw' follow
collect2: ld returned 1 exit status