このクラスが直接使用されたとき、または誰かがこのクラスから派生したときに警告を受け取るために、C++98 と g++ コンパイラを使用してクラスを非推奨としてマークしたいと思います。
どうやら、__attribute__ ((__deprecated__))
クラスが使用されている場合は using が機能しますが、継承では機能しません。
例えば:
#if defined(__GNUC__)
# define DEPRECATED __attribute__ ((__deprecated__))
#else
# define DEPRECATED
#endif
class DEPRECATED Foo
{
public:
explicit Foo(int foo) : m_foo(foo) {}
virtual ~Foo() {}
virtual int get() { return m_foo; }
private:
int m_foo;
};
class Bar : public Foo // This declaration does not produce a compiler
// warning.
{
public:
explicit Bar(int bar) : Foo(bar), m_bar(bar) {}
virtual ~Bar() {}
virtual int get() { return m_bar; }
private:
int m_bar;
};
int main(int argc, char *argv[])
{
Foo f(0); // This declaration produces a warning.
Bar b(0); // This declaration does not produce a warning.
return b.get();
}
「class Bar : public Foo」から警告が表示されることを期待しますが、そうではありません (g++ 5.2.1 でテスト済み)。
廃止されたクラスから派生するときに警告を表示する方法はありますか?