C++ header file problem with 4.16

Comment out every custom variable and function, but leave possibly added #includes.
If it compiles, check inside the editor “Edit → Editor Preferences → General → Source Code”, if “Visual Studio 2017” is selected and select it, if it isn’t.
Then close your solution and open your project folder and rightclick your “MyProject.uproject” and select “Generate Visual Studio project files”.

gl

PS. My source for the VS problem: answerhub

I’ve seen the same thing happen in both VS Professional/Enterprise 2015/2017; it’s almost always triggered by modifying the lines in a header before UCLASS() after the .generated file has been generated. However, it doesn’t normally manifest as a compiler error, it’s normally an Intellisense error.

To stamp out any potential intellisense issue, ensure that you’re reading the Output window in Visual Studio, not the Errors List window; the latter on occasion “lies” to you and there’s no compile error at all (it’s actually an Intellisense error, which is incorrectly reported). Also don’t trust the underline “squiggles” and “alt-text” messages; that’s intellisense also and won’t stop you from compiling.

Fixing Intellisense errors

If it does turn out to be an Intellisense issue; you should be able to select Project | Rescan Solution from the Visual Studio menu. I find that normally fixes all Intellisense issues.

(The method I recall on the forums was to change your build configuration, say if you’re using Debug Game Editor, switch to Development Game Editor, rebuild and switch back again. However I find this a bit of a clunky hack.)

Fixing compiler errors

If it is genuinely a compiler issue, it’s likely to be because of another error that caused UHT to fail and therefore the .generated file wasn’t re-written. So firstly I’d check you don’t have any other errors that UHT is raising and fix them first’ your error may just disappear. Again, from the Output window.

Failing the scientific approaches above, my recommendation would be (in ascending order of desperation)

  • Rebuild the solution (right click, Rebuild Solution)
  • Remove the Binaries folder from your project root and build
  • Remove Intermediate folder, right click the project and select Generate Visual Studio Project Files, then reopen the project, then build

Also ensure you have the editor closed when you perform these tasks to ensure you don’t end up building a “hot reload” DLL - these cause more issues than a straight compile.

Let me know how it goes, if you’re still stuck after all that (and I’d be surprised), then come back and we’ll see what we can do to help some more.

Ah thanks for the detailed feedback, A. I always wondered why in the forums people constantly recommended about switching configuration; I guess it must have been because they were on 2015.

The only thing close to a “proper solution” I could say try would be to turn off intellisense errors if they bug you that badly - Tools | Options → Text Editor | C/C++ | Advanced | Disable Error Reporting.

As stated I never have the error list window turned on (because it’s so poo, not just for UE4/C++). The output window always did the job fine before the Error List window came along in 2001, with its fancy colours and icons.

After upgrading to 4.16.1, changing the number of lines above the code block causes errors and can no longer be compiled.

When a header file is generated by the unreal editor, the code block starts at line nine:

9 UCLASS()

10 class TESTPROJECT_API AMyActor : public AActor

etc…

Simply adding or removing a blank line, adding a new #include, or anything else that causes the start of the code block to change up or down from line 9, cause it to no longer be recognized as valid with the error:

UCLASS(): " this declaration has no storage class or type specifier"

The project cannot be compiled with this error.

I was previously using 4.12.5 and didn’t have this problem, but after installing 4.16.1 and 4.16.2, projects that use 4.12.5 now have the same problem with their header files. This does not happen with non Unreal header files. It happens with both VS Community 2015 and VS Community 2017.

Any help would be appreciated.

Small improvement but the problem still persists.
Changed setting from Visual Studio to Visual Studio 2017.
Ran: “Generate Visual Studio project files”
Opened in UE and successfully compiled.
Opened in VS2017 with no errors and built solution successfully.
Added a new blank line above the code block in the header file and the problem returned.
This is all with a new project and no custom code, just the UE generated defaults for a new Actor class.

Switching from from Visual Studio to Visual Studio 2015/17 upgrades it from a compiler error to an Intellisense error. Rescan Solution removes the error temporarily for VS2017, but it doesn’t work for VS2015. Switching to DebugGame Editor, rebuilding, and switching back to Development Editor does work for VS2015. As soon as a new line is added above UCLASS() the Intellisense error returns but it still compiles. A proper solution would be preferred, but at least I can compile now. Thanks!

I am facing the same bug but I think a faster work around is to simply save your project, then close and reopen visual studio.

I think I have a resolution for this problem. In visual studio go to:
Tools ->Options → Text Editor → C/C++ → Advanced

Scroll down… find the option for “use forward slash in #include autocomplete”. Check that is set to true.

Simply anecdotal but I haven’t had this problem since I fixed that setting.