首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

Employee:Employee(const Employee& other):name(other.name), id(count) { +

2012-03-26 
Employee::Employee(const Employee& other):name(other.name), id(count) {++coC/C++ code//为什么出现//

Employee::Employee(const Employee& other):name(other.name), id(count) { ++co

C/C++ code
//为什么出现//undefined reference to `Employee::count'//.hclass Employee{    public:        Employee():name("NoName"), id(count)        {            ++count;        }        Employee(std::string strName):name(strName), id(count)        {            ++count;        }        virtual ~Employee();        Employee(const Employee& other);        Employee& operator=(const Employee& other);    protected:    private:        std::string name;        int id;        static int count;};//.cppEmployee::Employee(const Employee& other):name(other.name), id(count){    ++count;}


[解决办法]
类的static成员变量,必须在类的定义之外定义一次。

在 .cpp 中加上一行

int Employee::count = 0;
[解决办法]
另:不要忘了析构函数的实现,哪怕是空实现

热点排行