![]() |
#2
lintaoyn2011-09-27 20:37
|

//编的一个简单的通讯录的类 对静态成员的运用编译总是报错
class AddressBook
{
public:
AddressBook(string aName = "NULL",int aPhonenum = 0);
~AddressBook();
static int getLength();
static void addLength();
static void decLength();
void setName(string aName);
string getName();
void setPhonenum(int aPhonenum);
int getPhonenum();
private:
string m_strName;
int m_iPhonenum;
static int m_s_ilength;
};
AddressBook::AddressBook(string aName /* = "NULL" */,int aPhonenum /* = 0 */)
{
m_strName = aName;
m_iPhonenum = aPhonenum;
}
AddressBook::~AddressBook()
{
--m_s_ilength;
}
错误是AddressBook.obj : error LNK2001: 无法解析的外部符号 "private: static int AddressBook::m_s_ilength" (?m_s_ilength@AddressBook@@0HA)class AddressBook
{
public:
AddressBook(string aName = "NULL",int aPhonenum = 0);
~AddressBook();
static int getLength();
static void addLength();
static void decLength();
void setName(string aName);
string getName();
void setPhonenum(int aPhonenum);
int getPhonenum();
private:
string m_strName;
int m_iPhonenum;
static int m_s_ilength;
};
AddressBook::AddressBook(string aName /* = "NULL" */,int aPhonenum /* = 0 */)
{
m_strName = aName;
m_iPhonenum = aPhonenum;
}
AddressBook::~AddressBook()
{
--m_s_ilength;
}
求解