f**********t 发帖数: 1001 | 1 careercup 7.2:
这里CallHandler和Employee互相调。编译出现这个错:
1>.\design.cpp(432) : error C2065: 'Employee' : undeclared identifier
对于函数我们可以声明。class呢?
非常感谢 =)
class CallHandler {
static const int LEVELS = 3;
static const int NUM_FRESHERS = 5;
vector > employeeLevels(LEVELS);
public:
Employee dispatchCall(Call call) {
for (int level = call.getRank(); level < LEVELS; ++level) {
for (int i = 0; i < employeeLevels[level].size(); ++i) {
if (employeeLevels[level][i].free)
return employeeLevels[level][i];
}
}
}
};
class Employee {
int rank;
bool free;
CallHandler callHandler;
public:
void CannotHandle(Call call) {
call.rank = rank + 1;
callHandler.dispatchCall(call);
free = true;
callHandler.getNextCall(this);
}
}; |
h*******e 发帖数: 125 | 2 Use forward declaration:
Put class Employee at the top. |
f**********t 发帖数: 1001 | 3 But the class Employee will also use the class CallHandler. |
b***i 发帖数: 3043 | 4 class Employee;
【在 f**********t 的大作中提到】 : But the class Employee will also use the class CallHandler.
|
w****x 发帖数: 2483 | 5 careercup的设计题答案感觉都是over design |
f**********t 发帖数: 1001 | |
f**********t 发帖数: 1001 | 7 是说那些答案说得过多了?
【在 w****x 的大作中提到】 : careercup的设计题答案感觉都是over design
|