UE-c++ className.generated.h报错:generated header must be included last in a list of includes
为什么不把`#include xx.generated.h`放最后会导致`error "the .generated.h file should always be the last #include in a header"`?
一. 问题
为什么不把#include xx.generated.h
放最后会导致error "the .generated.h file should always be the last #include in a header"
?
二. 求助
三. 分析
大佬简短凝练的回答道:因为好识别!
不是其他奇奇怪怪的原因
然后我们想一下,识别 这个词,谁识别,识别谁,为什么会好识别?识别后来做啥?结合其包含的反射机制,可以引出很深的话题,这里不做探讨。
四. 总结
为了反射机制运行的方便。
五. 新的认识
UE的反射机制是根据宏生成对应的代码。
既然是C++,那么生成的代码自然是.h.cpp的组合。假设我们为类A生成了A.generated.h和A.generated.cpp(UE命名习惯)。如果类A的宏标记生成的代码想跟A.generated.h里我们生成的代码来个里应外合的话,此时A.h一般都需要include"A.generated.h"。
另一方面,用户对背后的代码生成应该是保持最小惊讶的,用户写下了A.h,他在使用的时候自然也会想include “A.h”,所以这个时候我们的A.generated.h就得找个方式一起安插进来,最方便的方式莫过于直接让“A.h” include “A.generated.h”了。那既然每个需要分析的文件最后都会include这么一个*.generated.h,那自然就可以把它本身就当作一种标记了。
UE目前的方案是每个要分析的文件加上该include并且规定只能当作最后一个include,放最后也是因为他担心会有各种宏定义顺序产生的问题。
更多推荐
所有评论(0)