C++ 错误预期为“;”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19537511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error expected a ';'
提问by user2881555
I have the following code, an error IntelliSense: expected a ';'
is reported at the line indicated:
我有以下代码,IntelliSense: expected a ';'
在指示的行报告错误:
回答by Some programmer dude
Your actual code is like this:
你的实际代码是这样的:
Dictionary::Dictionary() {
...
Word* fromRecord(const string &theWord,
const string &theDefinition,
const string &theType)
{
...
}
...
}
In other words, you define a function withina function. This is not allowed.
换句话说,您在函数内定义了一个函数。这是不允许的。
回答by Manohar Reddy Poreddy
I was missing a semicolon
我少了一个分号
struct Node {
int data;
Node* left;
Node* right;
}; // <---------- was missing a semicolon here
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
Adding a semicolon solved the issue.
添加分号解决了这个问题。
回答by user2910812
I assume fromRecord is either a function call or constructor. So you are missing a colon before opening a new scope
我假设 fromRecord 是函数调用或构造函数。所以你在打开一个新的范围之前缺少一个冒号
Word* fromRecord(const string &theWord,
const string &theDefinition,
const string &theType); <- Here
If your intent is to create an inner function then look at lambdas.
如果您的意图是创建内部函数,请查看 lambdas。