regarding A..
A = factory B = product
A' = special factory B' = special product
class IHardware { }; class MaschineController : public IHardware { }; class TraktorKontrol : public IHardware { }; class IFactory { public: virtual IHardware *createHardware() const = 0; }; class MaschineFactory : public IFactory { public: MaschineController *createHardware() const override; }; class TraktorFactory : public IFactory { public: TraktorKontrol *createHardware() const override; };
§ 10.3.7 Virtual functions The return type of an overriding function shall be either identical to the return type of the overridden function or covariant with the classes of the functions. If a function D::f overrides a function B::f, the return types of the functions are covariant if they satisfy the following criteria:
class IFactory { public: virtual const IHardware *createHardware() const = 0; }; class MaschineFactory : public IFactory { public: MaschineController *createHardware() const override; }; class TraktorFactory : public IFactory { public: TraktorKontrol *createHardware() const override; };
class IHardware { public: virtual const char *getBrand() const = 0; }; class MaschineController : public IHardware { public: char *getBrand() const override; }; class TraktorKontrol : public IHardware { public: char *getBrand() const override; };
Comprehensive Wikipedia article
http://en.wikipedia.org/wiki/Covariance_and_contravariance_(computer_science)
What's New in Standard C++[98]?
http://www.drdobbs.com/whats-new-in-standard-c/184403580
Good answer for cv-qualifiers on covariant return types
http://stackoverflow.com/a/3593613