弃用未使用的虚拟方法 [英] deprecate unused virtual method
问题描述
这里有一个例子来说明我的问题:
Here's an example to illustrate my issue :
class Foo1
{
virtual void FooMethod() __attribute__((deprecated)) = 0;
};
class Foo2 : public Foo1
{
virtual void FooMethod() = 0;
};
我的课程 Foo1
具有纯虚拟方法 FooMethod
。我不希望用户再使用它。我想让他们在继承的类 Foo2
中使用此方法。
Foo1 :: FooMethod()
已被弃用并放在 Foo2
中: Foo2 :: FooMethod()
。 Foo2 :: FooMethod()
然后是 Foo1 :: FooMethod();
My class Foo1
has a pure virtual method FooMethod
. I don't want user to use it anymore. I want to make them use this method in the inherited class Foo2
.
Foo1::FooMethod()
is so deprecated and put in Foo2
: Foo2::FooMethod()
. Foo2::FooMethod()
is then an override of Foo1::FooMethod();
如果用户尝试重载 Foo1 :: FooMethod()
,他将收到编译警告。
我的问题是,如果用户覆盖 Foo2 :: FooMethod()
,他也会收到警告。
If the user try to overload Foo1::FooMethod()
, he will get a compilation warning.
My issue is, if the user override Foo2::FooMethod()
, he also gets a warning.
如何实现不赞成重载 Foo1 :: FooMethod()
,必须覆盖 FooMethod()
通过 Foo2
。为了兼容,我无法删除 Foo1 :: FooMethod()
。
How can I implement "Overload Foo1::FooMethod()
is deprecated, you must override FooMethod()
through Foo2
". I can't delete Foo1::FooMethod()
for compatibility.
谢谢!
推荐答案
如何实现不赞成重载Foo1 :: FooMethod(),必须通过Foo2重载FooMethod()。 。为了兼容性,我无法删除Foo1 :: FooMethod()。
How can I implement "Overload Foo1::FooMethod() is deprecated, you must overload FooMethod() through Foo2". I can't delete Foo1::FooMethod() for compatibility.
在这一点上,您正在造成如此混乱设计(:P),我会坚持使用文档。
At this point, you're causing such a mess in your design (:P) that I would stick with documentation.
告诉您的用户该功能已被弃用,不应该使用,然后继续。
Tell your users that the function is deprecated and shouldn't be used, then move on.
这篇关于弃用未使用的虚拟方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!