【发布时间】:2012-01-26 20:40:50
【问题描述】:
我对我现在遇到的一个错误有点困惑。我班上有一个getter/setter。 setter 将枚举作为参数,getter 应返回此枚举。但是,我收到了 getter 的这个错误:
错误:C2143:语法错误:缺少';'在“会话::类型”之前
好像SessionType 未定义。但是我没有得到同样的二传手错误。有什么理由吗?有没有办法解决这个错误?
(顺便说一句,如果我返回 int,它编译得很好,但我宁愿让 getter 与 setter 保持一致)
这是我的代码:
Session.h
class Session {
public:
enum SessionType {
FreeStyle,
TypeIn,
MCQ
};
explicit Session();
SessionType type() const;
void setType(SessionType v);
private:
SessionType type_;
}
Session.cpp:
SessionType Session::type() const { // ERROR!!
return type_;
}
void Session::setType(SessionType v) { // No error?
if (type_ == v) return;
type_ = v;
}
【问题讨论】: