From e4281fb3c8732baa0b5b67c77642c1a012f6250f Mon Sep 17 00:00:00 2001 From: Sudarsana Babu Nagineni Date: Fri, 27 Jul 2018 23:46:50 +0300 Subject: Update DEVELOPING.md Added a section about inheriting constructors (e.g. using Base::Base;) issue on the compilers which has only partial C++11 support. --- DEVELOPING.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/DEVELOPING.md b/DEVELOPING.md index f70d1f94ea..d865a35d2d 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -121,3 +121,48 @@ used/needed but we had one incident fixed by #9665. ### Workarounds - Copy & Pasteā„¢ the code. + + +## [Inheriting Constructors](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2540.htm) + +Compilers with only partial C++11 support causes compilation errors when using-declaration is used in derived class to inherit its base class's constructors `(e.g. using Base::Base;)`. + +```C++ +#include + +template +struct Varargs : std::vector +{ + using std::vector::vector; +}; + +// error: conflicts with version inherited from 'std::__1::vector >' +int main() +{ + Varargs v; + return 0; +} +``` + +### Workarounds + +- Replace using-declaration (e.g. using Base::Base;) in derived class with `universal forwarding constructor`. + +```C++ +#include + +template +struct Varargs : std::vector +{ + template + Varargs(Args&&... args) : std::vector(std::forward(args)...) {} +}; + +int main() +{ + Varargs v; + return 0; +} +``` + +Note: Using `universal forwarding constructor` may not be appropriate when derived class has additional members that are not in base class. Write constructors for the derived class explicitly instead of using `universal forwarding constructor` when the derived class has additional members. -- cgit v1.2.1