QWebView类有什么区别;与#include相比
这些定义有什么区别;
#include "QWebView" class QWebView;
What's difference between these defining;
#include "QWebView" class QWebView;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
class QWebView;
是所谓的前向声明。这意味着,在类型完全声明之前,您无法访问类的详细信息(例如方法/公共变量)。前向声明仅告诉编译器该特定类型存在,而完整的包含则告诉编译器该类提供了哪些方法等。如果您只是不想在声明中使用该类型,也可以。但是,一旦您调用
QWebView
类型的变量上的方法,如果您不包含完整的声明,您就会收到错误。class QWebView;
is a so called forward declaration. That means, you can't access details of the class (like methods/public variables) until the type is completely declared. The forward declaration, only tells the compiler that this particular type exists, whereas the full include tells the compiler, what methods etc. that class provides.If you just wan't to use the type in a declaration, it's fine. But as soon, as you call a method on a variable of type
QWebView
, you will get an error, if you don't include the full declaration.