[Interest] deprecating class methods gracefully

Allan Sandfeld Jensen kde at carewolf.com
Sun Nov 6 23:21:23 CET 2016


On Sunday 06 November 2016, René J.V. Bertin wrote:
> Hi,
> 
> This isn't essentially a Qt-specific question, but one about a situation I
> hope Qt may have found an elegant solution for.
> 
> Say I have a class (B) that at first I thought would need a (static) method
> with a mode argument with a default setting. That method is declared
> inline but that shouldn't make a difference, I think. It also overrides a
> method from the parent class (A), which is more relevant. Over time I've
> come to realise that the mode argument is moot for this particular method,
> because there is no justified use case for the non-default mode.
> 
> I could simply remove the method in question so that code builds to use the
> now no longer overridden parent method. However, this class is provided by
> a low-level library that's used by lots of code, and I'd prefer not to
> oblige all that code to be rebuilt immediately.
> 
> So what I'm looking for is a way to provide the function so that runtime
> dependencies of existing binaries continue to be satisfied, but in such a
> way that newly built code no longer references it.
> 
> Sadly this class was never designed for this, so there's no private
> implementation hidden behind a d-pointer which would make this a trivial
> problem.
> 
> Any suggestions how to tackle this problem? My current solution suppresses
> the class B definition in the headerfile when it's being included in the
> class A implementation file, and puts a transitional implementation of
> class B containing only the deprecated method in that implementation file.
> That seems to work, but feels like a hack ...
> 
If it is just a static method, you can just move the whole thing to a separate 
cpp file. It doesn't need to be declared with the rest of the class. 

Note that just makes it ABI compatible, but not source compatible. The usual 
method for source compatible is just declaring it deprecated, C++ has function 
attributes for that now.

`Allan



More information about the Interest mailing list