//// 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