我有头文件:
#ifndef VIP_TICKET_H
#define VIP_TICKET_H
#include "ticket.h"
class VIPTicket : public Ticket
{
public:
enum VIPType { FIRST_CLASS, FAST_LINE };
VIPType getTicketType() const;
private:
VIPType type;
};
#endif
它是cpp文件
#include "vipTicket.h"
VIPType VIPTicket::getTicketType() const
{
return type;
}
错误显示“错误C2143:语法错误:缺少';'在'VIPTicket :: getTicketType'“
之前这个错误非常令人困惑..我想这不是';'这是缺少的,但可能是代码中的其他问题,我无法指责..
答案 0 :(得分:7)
问题在于这个定义
VIPType VIPTicket::getTicketType() const
{
...
}
定义此函数时,您必须记住VIPType
不在全局范围内,而是在VIPTicket
类的范围内,因此您必须明确提及范围:
VIPTicket::VIPType VIPTicket::getTicketType() const
{
...
}