错误应为";"

Error expected a ';'

本文关键字:错误      更新时间:2023-10-16

我有以下代码,在指示的行IntelliSense: expected a ';'报告错误:

你的实际代码是这样的:

Dictionary::Dictionary() {
    ...
    Word* fromRecord(const string &theWord,
        const string &theDefinition,
        const string &theType)
    {
        ...
    }
    ...
}

换句话说,您可以在函数定义函数。这是不允许的。

我缺少一个分号

struct Node {
    int data;
    Node* left;
    Node* right;
};  // <---------- was missing a semicolon here
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

添加分号解决了这个问题。

我假设fromRecord要么是函数调用,要么是构造函数。因此,在打开新作用域之前缺少冒号

Word* fromRecord(const string &theWord,
    const string &theDefinition,
    const string &theType); <- Here

如果您的目的是创建一个内部函数,请查看 lambda。