类(class)的问题,如果两个类互相调用怎么办# JobHunting - 待字闺中
f*t
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);
}
};
这里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
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);
}
};