2010-09-05 136 views
-3
//// header file 

#ifndef _SECTION_ 
#define _SECTION_ 

#include <map> 
#include "Employee.h" 
using namespace std; 

class Section { 
private: 
    char* m_sectionName; 
    Employee* m_director; 
    Employee* m_viceDirector; 
    typedef multimap<string,Employee*> m_employees; 

public: 

    Section (char* name); 
    Section(const Section& section); 
    ~Section(); 

    const char* GetSectionName() const { return m_sectionName; } 
    const Employee* GetDirector() const { return m_director; } ///////////////check 
    const Employee* GetViceDirector() const {return m_viceDirector; } ///////////// check 

    void SetSectionName (const char* newName); 
    Employee* SetDirector (Employee& newDirector); ///////////// check 
    Employee* SetViceDirector (Employee& newViceDirector); ///////////// check 

    void Show() const; 
    void ShowEmployess() const; 
    void AddEmployee (Employee newEmployee); 
    Employee RemoveEmployee (string id); 

    int GetMinEmployeeWage() const; 
    int GetMaxEmployeeWage() const; 
    int AvgMaxEmployeeWage() const; 
    int GetNumOfEmployee() const; 
    int GetSumOfExpenses() const; 
}; 

#endif 



////// cpp 


#include "Section.h" 

Section::Section (char* name) 
{ 
SetSectionName(name); 
} 


Section::Section(const Section& otherSection) { 
SetSectionName(otherSection.GetSectionName()); 
m_director = otherSection.m_director; //////// check 
m_viceDirector = otherSection.m_viceDirector; /////// check 
} 

Section::~Section(){ 
delete [] m_sectionName; 
} 


void Section::SetSectionName (const char* newName){ 
m_sectionName = new char[strlen(newName)+1]; 
strcpy(m_sectionName, newName); 
} 


Employee* Section::SetDirector (Employee& newDirector) { 
Employee* oldDirector = m_director; 
m_director = &newDirector; 
return oldDirector; 
} 

Employee* Section::SetViceDirector (Employee& newViceDirector) { 
Employee* oldViceDirector = m_viceDirector; 
m_viceDirector = &newViceDirector; 
return oldViceDirector; 
} 

void Section::Show() const { 
cout <<"Section :"<<m_sectionName<<endl; 
cout <<"Director :"<<m_director<<endl; 
cout <<"ViceDirector :"<<m_viceDirector<<endl; 
} 


/*void Section::ShowEmployess() const { 
m_employees::iterator Iterator; 
for (Iterator index = m_employees.begin(); index != m_employees.end(); ++index) { 
    Iterator-> 
} 
}*/ 

///here the problem !! 
void Section::AddEmployee(Employee newEmployee) { 
m_employees.insert(make_pair((string)(newEmployee->GetLastName()),newEmployee)); 
} 
+4

下一次請在編輯頁面使用'101010'按鈕來設置你的代碼的格式,而且這裏的大多數人都不願意看到你剛纔傾倒在這裏的代碼量。問題到10-15行,理想情況下是自包含的(即不需要其他頭文件)。最後,你應該花時間來制定一個合適的問題,沒有這個,我投票結束這個問題並不是一個真正的問題。 – sbi 2010-09-05 20:58:04

+1

呃,錯誤是什麼? – SoapBox 2010-09-05 20:58:48

+2

你甚至試圖看看這個問題嗎? – Patrick 2010-09-05 20:59:06

回答

2
typedef multimap<string,Employee*> m_employees; 

使m_employees成爲專用地圖類型的別名。你需要定義一個成員。改用:

typedef multimap<string,Employee*> EmpMap; 
EmpMap m_employees; 
+0

擊敗我16秒! – Potatoswatter 2010-09-05 21:02:34

+0

@Patatoswatter:哈哈。我以爲我越來越慢...... ;-) – dirkgently 2010-09-05 21:03:29

1

M_EMPLOYEES不是一個變量,它是一個類型名稱(從科類的頭typedef的在同一行,你是使用newEmployee,就好像它是一個指向Employee實例,但是。它實際上是一個副本實例

相關問題