diff options
author | Sudarsana Babu Nagineni <sudarsana.babu@mapbox.com> | 2018-07-27 23:46:50 +0300 |
---|---|---|
committer | Sudarsana Babu Nagineni <sudarsana.babu@mapbox.com> | 2018-07-30 12:38:24 +0300 |
commit | e4281fb3c8732baa0b5b67c77642c1a012f6250f (patch) | |
tree | d01beabeb1e4fcb7604b588f03a3b371a8d9f778 /DEVELOPING.md | |
parent | 9561b6c11563be8cc040b121052ffa93016a5cac (diff) | |
download | qtlocation-mapboxgl-e4281fb3c8732baa0b5b67c77642c1a012f6250f.tar.gz |
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.
Diffstat (limited to 'DEVELOPING.md')
-rw-r--r-- | DEVELOPING.md | 45 |
1 files changed, 45 insertions, 0 deletions
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 <vector> + +template <typename T> +struct Varargs : std::vector<T> +{ + using std::vector<T>::vector; +}; + +// error: conflicts with version inherited from 'std::__1::vector<int, std::__1::allocator<int> >' +int main() +{ + Varargs<int> v; + return 0; +} +``` + +### Workarounds + +- Replace using-declaration (e.g. using Base::Base;) in derived class with `universal forwarding constructor`. + +```C++ +#include <vector> + +template <typename T> +struct Varargs : std::vector<T> +{ + template <class... Args> + Varargs(Args&&... args) : std::vector<T>(std::forward<Args>(args)...) {} +}; + +int main() +{ + Varargs<int> 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. |