//// 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));
}
-3
A
回答
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實例,但是。它實際上是一個副本實例
相關問題
- 1. C2143:語法錯誤:缺少';'在'*'之前
- 2. C語法 - 錯誤C2143:語法錯誤:在'*'之前缺少')'
- 3. afxtempl.h錯誤12錯誤C2143:語法錯誤:缺少';'在'}'之前
- 4. 錯誤C4430:與錯誤C2143:語法錯誤:缺少';'之前'*'
- 5. 錯誤C2143:語法錯誤:缺少';'聲明指針前'*'之前
- 6. 編譯錯誤C2143:語法錯誤:缺少';'之前'<'
- 7. 錯誤C2143:語法錯誤:缺少';'之前'<'C++
- 8. 錯誤C2143:語法錯誤:缺少';'之前「__stdcall‘
- 9. 錯誤C2143:在'常量'之前缺少語法錯誤')'
- 10. C++:錯誤C2143:語法錯誤:缺少';'之前'<'
- 11. 錯誤C2143:語法錯誤:缺少';'在'模板'之前
- 12. 錯誤C2143:語法錯誤:缺少';'之前,「<」
- 13. 錯誤C2143:語法錯誤:缺少';'在Visual C++的'*'之前
- 14. 錯誤C2143:語法錯誤:缺少')'之前'&'
- 15. 錯誤C2143:語法錯誤:缺少';'之前 '*'
- 16. Visual C++錯誤C2143:語法錯誤:缺少';' 'constant'之前
- 17. 錯誤C2143:語法錯誤:缺少','之前':'
- 18. C++/cli錯誤C2143:語法錯誤:缺少';'之前'。'
- 19. 錯誤C2143:語法錯誤:缺少';' 'if'
- 20. 錯誤C2143:語法錯誤:缺少';'
- 21. 錯誤C2143:語法錯誤:缺少';'在'^'
- 22. 錯誤錯誤C2143:語法錯誤:缺少';'前「<class-head>」
- 23. 錯誤類型C2143 - 缺少','之前'<'
- 24. 錯誤C2143:語法錯誤:缺少 ';' 'constant'前
- 25. 錯誤C2143:語法錯誤:缺少「;」 (在「。」前面)
- 26. 未知課程? C2143語法錯誤:缺少「;」在'*'之前
- 27. 錯誤C4430:缺少類型說明符/錯誤C2143:語法錯誤:缺少';'之前'*'
- 28. 模板類拋出錯誤C2143:語法錯誤:缺少';'之前'<'
- 29. 錯誤C2143和錯誤C2059缺少「;」之前「{」
- 30. 缺少語法錯誤; *前
下一次請在編輯頁面使用'101010'按鈕來設置你的代碼的格式,而且這裏的大多數人都不願意看到你剛纔傾倒在這裏的代碼量。問題到10-15行,理想情況下是自包含的(即不需要其他頭文件)。最後,你應該花時間來制定一個合適的問題,沒有這個,我投票結束這個問題並不是一個真正的問題。 – sbi 2010-09-05 20:58:04
呃,錯誤是什麼? – SoapBox 2010-09-05 20:58:48
你甚至試圖看看這個問題嗎? – Patrick 2010-09-05 20:59:06