zoukankan      html  css  js  c++  java
  • 学习C++——只声明忘记定义了

    #include <iostream>
    #include <list>
    #include <string>
    
    using namespace std;
    class Employee
    {
        string family_name;
        short department;
    public:
        Employee(const string& name,int dept);
        virtual void print() const;
    };
    Employee::Employee(const string& name,int dept):family_name(name),department(dept){}
    void Employee::print() const
    {
        cout << family_name << '	' << department << endl;
    }
    
    class Manager:public Employee
    {
        list<Employee*> group;
        short level;
    public:
        Manager(const string& name,int dept,int lvl);
        void print() const;
    };
    Manager::Manager(const string& name,int dept,int lvl):Employee(name,dept),level(lvl){}
    void Manager::print() const
    {
        Employee::print();
        cout << "	level" << level << endl;
    }
    void print_list(const list<Employee*>& s)
    {
        for(list<Employee*>::const_iterator p=s.begin();p!=s.end();++p)
            (*p)->print();
    }
    
    int main()
    {
        //cout << "Hello world!" << endl;
        Employee e("Brown",1234);
        Manager  m("Smith",1234,2);
        list<Employee*> empl;
        empl.push_front(&e);
        empl.push_front(&m);
        print_list(empl);
        return 0;
    }

    废话少说,直接上代码;红色部分,就是当初自己以为是声明定义的,但是后来才发现,我居然把声明当定义来用,硬伤啊。

  • 相关阅读:
    redis安装及简单命令
    struts2 第二天
    初学struts2-入门案列
    hibernate第二天
    hibernate入门
    同义词,索引,表分区
    表空间,序列
    orcale函数
    orcale错题分析
    orcale开篇
  • 原文地址:https://www.cnblogs.com/awy-blog/p/3388092.html
Copyright © 2011-2022 走看看