I would like to mark the class as deprecated using C ++ 98 and the g ++ compiler to get a warning when this class is used directly or when someone comes from this class.
Usage seems to __attribute__ ((__deprecated__))work when a class is used, but not for inheritance.
For example:
#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
{
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);
Bar b(0);
return b.get();
}
I expect to receive a warning from the "class Bar: public Foo", but it is not (tested with g ++ 5.2.1).
Is there a way to get a warning when outputting from an obsolete class?
source
share