C++ "multiple types in one declaration" error
C++C++ Problem Overview
Why do I get the "multiple types in one declaration"
error when I compile my C++ program?
C++ Solutions
Solution 1 - C++
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;
Solution 2 - C++
Don't forget to check for ;
after enum declarations, too.
Solution 3 - C++
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.
Solution 4 - C++
You must have declared twice the same variable in some class or two classes with the same name. See this on Stack Overflow, for example.
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!
Solution 5 - C++
My guess is you're missing a closing brace somewhere in a class definition, or a semicolon after it.
Solution 6 - C++
Also, you may have forgotten a semicolon in a forward declaration:
class Foo // <-- forgot semicolon
class Bar {
...
};
Solution 7 - C++
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
};
};
Solution 8 - C++
;
) at the end of a class, enum, or struct definition
C or C++ error: "multiple types in one declaration": Further explanation for the case where you simply forgot the semicolon (Imagine you have the following code:
enum class ErrorType {
MY_ERROR_1 = 0,
MY_ERROR_2,
MY_ERROR_3,
/// Not a valid value; this is the number of enums
_COUNT,
} // <====== MISSING SEMICOLON (;)!
class MyClass {
public:
// some stuff
private:
// some stuff
};
Since I forgot the semicolon (;
) at the end of the enum class
definition, after the curly brace, it looks like I am defining the entire class MyClass
inside of the enum class ErrorType
, so I get the error!:
> ../my_header.h:43:1: error: multiple types in one declaration > 43 | }; > | ^
...where line 43 in my case is at the end of the class MyClass
definition.
SOLUTION: add the missing semicolon (;
) at the end of the enum
definition, as stated by @eguaio here and @MSalters here.
Solution 9 - C++
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.