NS_OVERRIDE 编辑
NS_OVERRIDE
is a macro which allows C++ code in Mozilla to specify that a method is intended to override a base class method. If there is no base class method with the same signature, a compiler with static-checking enabled will fail to compile.
NS_OVERRIDE
is declared in nscore.h, beginning with Gecko 2.0. It was introduced in bug 500870.
Example
Class A has a method GetFoo()
which is overridden by class B:
class A { virtual nsresult GetFoo(nsIFoo** aResult); }; class B : public A { NS_OVERRIDE virtual nsresult GetFoo(nsIFoo** aResult); };
Later, the signature of A::GetFoo()
is changed to remove the output parameter:
class A { - virtual nsresult GetFoo(nsIFoo** aResult); + virtual already_AddRefed<nsIFoo> GetFoo(); };
B::GetFoo()
no longer overrides A::GetFoo()
as was originally intended. A compiler with static-checking enabled will issue the following error:
test.cpp:8: error: NS_OVERRIDE function B::GetFoo(nsIFoo**) does not override a base class method with the same name and signature.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论