C++错误C2143语法错误: missing ';' before function name

标签 c++ syntax-error

我有头文件:

#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/

相关文章:

c++ - 在 C++ 中,std::string::push_back() 的摊销复杂度是 O(1) 吗?

C++:需要帮助理解运算符重载错误

python - Kivy Pong教程语法错误: invalid syntax

python - Python : elif statement showing “syntaxError: Invalid Syntax” [duplicate]

c++ - 确保库函数可以内联的一体化模块方法

c++ - 组合 & 和 * 运算符

c++ - 重载解决算法中的歧义是如何确定的?

jquery - jQuery if/else意外 token : punch ({)

syntax-error - 如何在 Isabelle 中正确使用关键字 'theorem'?

macos - 找不到 hadoop start-xxx.sh 命令和语法错误