| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1004 人关注过本帖
标题:怎么写派生类的赋值构造函数啊
只看楼主 加入收藏
q236763612
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2008-10-22
收藏
 问题点数:0 回复次数:0 
怎么写派生类的赋值构造函数啊
怎么写基类的析构函数,我错在哪!
怎么写派生类的赋值构造函数,我错在哪里!
#include<string>

#include<iostream>
#include<cassert>
using namespace std;
class Employee
{private:
    string name;
    int     ID;
public:
    Employee(char* a, int b)
        :name(a),ID(b)
    {}
    Employee (const Employee& s)
    {
        assert(this!=& s);
        name=s.name;
        ID=s.ID;}
Employee& operator=(const Employee& rhs)
{
    assert(this!=&rhs);
    name=rhs.name;
    ID=rhs.ID;
  return *this;
}
~Employee()
{
    //这里怎么写析构函数。
    }
};
class Manager:public  Employee
{
private:
    int sal;
public:
    Manager(char*a, int b, int c)
        :Employee(a,b),
        sal(c)
    {}
Manager(const Manager& s)
:Employee(s)
{ sal=s.sal;}
//这里怎么写赋值构造函数。下面的代码错在哪怎么修改啊!
//Manager& operator=(const Manager& rhs)
//:Employee(rhs)
//{  // ID=rhs.ID;
 //   name=rhs.name ;

//    sal=rhs.sal;
//    return *this;}
};
int main ()
{
    Employee E("fuwei" ,236763612);
    Manager F(" xiaoke", 236763613 , 5000);
    E=F;
cin.get();}
搜索更多相关主题的帖子: 赋值 派生类 函数 构造 
2008-11-05 09:47
快速回复:怎么写派生类的赋值构造函数啊
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013197 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved