我有头文件:
#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;
}
错误显示“error C2143: syntax error : missing ';'在 'VIPTicket::getTicketType' 之前 "
这个错误非常令人困惑..我猜它不是';'那是丢失的,但可能是我无法确定的代码有其他问题..
最佳答案
问题是这个定义
VIPType VIPTicket::getTicketType() const
{
...
}
当你定义这个函数时,你必须记住 VIPType
不在全局范围内,而是在 VIPTicket
类的范围内,所以你必须明确提及范围:
VIPTicket::VIPType VIPTicket::getTicketType() const
{
...
}
关于C++错误C2143语法错误: missing ';' before function name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33064427/