QWebView类有什么区别;与#include相比

发布于 2024-09-12 06:14:58 字数 69 浏览 0 评论 0原文

这些定义有什么区别;

#include "QWebView"

class QWebView; 

What's difference between these defining;

#include "QWebView"

class QWebView; 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩发小公举 2024-09-19 06:14:58

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文