//// 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. C語法 - 錯誤C2143:語法錯誤:在'*'之前缺少')'
- 2. afxtempl.h錯誤12錯誤C2143:語法錯誤:缺少';'在'}'之前
- 3. Visual C++錯誤C2143:語法錯誤:缺少';' 'constant'之前
- 4. 錯誤C2143:語法錯誤:缺少';'之前,「<」
- 5. 錯誤C2143:在'常量'之前缺少語法錯誤')'
- 6. C++:錯誤C2143:語法錯誤:缺少';'之前'<'
- 7. C++/cli錯誤C2143:語法錯誤:缺少';'之前'。'
- 8. 錯誤C2143:語法錯誤:缺少';' 'if'
- 9. 錯誤C2143:語法錯誤:缺少';'在'^'
- 10. 錯誤錯誤C2143:語法錯誤:缺少';'前「<class-head>」
- 11. 錯誤類型C2143 - 缺少','之前'<'
- 12. 錯誤C2143:語法錯誤:缺少 ';' 'constant'前
- 13. 錯誤C2143和錯誤C2059缺少「;」之前「{」
- 14. 缺少語法錯誤; *前
- 15. Awesomium C++:語法錯誤:缺少';'之前'*'
- 16. 語法錯誤:缺少';'之前'。'
- 17. 語法錯誤:缺少';'之前')'
- 18. 語法錯誤:缺少';'在'type'之前
- 19. 錯誤C2146:語法錯誤:缺少';'之前標識符'ContextRecord'
- 20. 錯誤C2146:語法錯誤:缺少';'之前標識符'頂點'
- 21. 錯誤C2146:語法錯誤:缺少';'在標識符'g_App'之前
- 22. 錯誤缺少 '語句之前' - @import
- 23. 語法錯誤:缺少;陳述前?
- 24. JavaScript - 缺少語法錯誤
- 25. BASH語法錯誤 - [:缺少']」
- 26. 鏈接列表錯誤:語法錯誤:缺少';'在標識符'head'之前
- 27. C++,語法錯誤:缺少';'之前標識符'N0'
- 28. 實現跳過列表,語法錯誤:在'之前'缺少')';'
- 29. 語法錯誤:缺少;在正常聲明之前的聲明
- 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