There is a bug in my file. It is clear that there is #pragma once in my header file, but there will always be repeated errors including the generated file during compilation. Every time I compile, I add another line #pragma once to my header file, or remove it if there are two lines. In short, I need to modify the header file to avoid errors for the time being. There is only one class with this problem. I don’t know the reason temporarily, because the code has no errors at all. I looked at the generated file and found that #pragma once was missing. If each generated file has #pragma once, this problem may be solved.
MyCode:
Anecdotal obviously but every project I’ve worked on code standards required #pragma once at the top of every header.
Me Too, But had some wrong make my #pragma once not work(If the header file has not been changed since the last compilation).
I was forced to modify the problematic header file every time before compilation. Even if I added a space, the compilation could pass, but it could only take effect once, and the second compilation could not take effect. So I said there was no problem with the code.
Maybe if the code is not modified, the last compiled cache prevents the compiler from reading my #pragma once.
And, my Class.h was not been multi include, but Class.generated.h was been multi include. and i have not include Class.generated.h in other head.
This phenomenon of writing code normally but having strange problems really makes me unable to know why. If only the engine could do something to deal with this strange bug.
My code:
报错 笔记
Hmm I have never seen that problem. AFAIK you should only ever need pragma once a single time at the top of the file. Every header on every project I have shipped starts just like below.
When you add new code files do you regenerate the project? That could cause weird issues if not…
I found the cause of the error because I mistakenly included the generated file in the header file of another struct. Maybe I accidentally chosed it when copying the code.
Thank you @cloodshop That was the case for me too. I just had to trawl through my classes looking for it.