C ++“一个声明中的多种类型”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1753189/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 21:05:33  来源:igfitidea点击:

C++ "multiple types in one declaration" error

c++

提问by Mark Copeland

Why do I get the "multiple types in one declaration"error when I compile my C++ program?

为什么"multiple types in one declaration"在编译 C++ 程序时会出现错误?

回答by MSalters

You probably have code that's the equivalent of

你可能有相当于

int float x;

probably

大概

class Foo { } float x;

or in it's more common form (note the missing semicolon after closing curly bracket)

或者更常见的形式(注意关闭大括号后缺少分号)

class Foo {
  //
}

float x;

回答by Narek

I had the same problem. Sometimes the error line does not show the correct place. Go through all new-created/modified classes and see if you forget ";" in the end of class defifnition.

我有同样的问题。有时错误行没有显示正确的位置。浏览所有新创建/修改的类,看看您是否忘记了“;” 在类定义的末尾。

回答by eguaio

Don't forget to check for ;after enum declarations, too.

不要忘记检查;枚举声明之后。

回答by RageZ

You must have declared twice the same variable in some class or two classes with the same name. See thison Stack Overflow, for example.

您必须在某个类或两个具有相同名称的类中声明两次相同的变量。例如,在 Stack Overflow 上查看内容。

You could be also missing a ;or you could have a class definition with broken syntax ...

您可能还缺少一个,;或者您可能有一个语法错误的类定义......

If you can show us some code, that would be better!

如果您可以向我们展示一些代码,那就更好了!

回答by Grumdrig

My guess is you're missing a closing brace somewhere in a class definition, or a semicolon after it.

我的猜测是您在类定义中的某处缺少一个右大括号,或者在它之后缺少一个分号。

回答by Joe A

Also, you may have forgotten a semicolon in a forward declaration:

此外,您可能忘记了前向声明中的分号:

class Foo // <-- forgot semicolon

class Bar {
  ...
};

回答by bhathiya-perera

Here is a yet another scenario that can pop up the same error

这是另一个可以弹出相同错误的场景

struct Field
{   // <------ Forget this curly brace
    enum FieldEnum
    {
        FIRSTNAME,
        MIDDLENAME,
        LASTNAME,
        UNKNOWN
    };
};

回答by haldavitt

Agree with the above. Also, if you see this, preprocess the app and look at the .i Search for the "offending" name. Then look back up. You'll often see the "}" w/o ";" on a class in the first non-with space above. Finding the problem is often harder than knowing what it is.

同意楼上的。此外,如果您看到这一点,请预处理应用程序并查看 .i 搜索“违规”名称。然后回头看。你会经常看到没有“;”的“}” 在第一个不带空格的类上。发现问题往往比知道它是什么更难。