inheriting-constructors

Inheriting constructors and virtual base classes

旧城冷巷雨未停 提交于 2019-12-23 09:12:19
问题 I'm about to create an exception class hierarchy which conceptually looks somewhat like this: #include <iostream> #include <stdexcept> class ExceptionBase : public std::runtime_error { public: ExceptionBase( const char * msg ) : std::runtime_error(msg) {} }; class OperationFailure : virtual public ExceptionBase { public: using ExceptionBase::ExceptionBase; }; class FileDoesNotExistError : virtual public ExceptionBase { public: using ExceptionBase::ExceptionBase; }; class

C++11 inheriting constructors and access modifiers

爷,独闯天下 提交于 2019-12-17 06:11:36
问题 Assuming the following layout: class Base { protected: Base(P1 p1, P2 p2, P3 p3); public: virtual void SomeMethod() = 0; } class Derived : public Base { public: using Base::Base; public: virtual void SomeMethod() override; }; Should I be able to specify Derived 's constructor as public here? VC++ gives the following error: cannot access protected member declared in class 'Derived' compiler has generated 'Derived::Derived' here [points to the using Base::Base line] see declaration of 'Derived'

noexcept, inheriting constructors and the invalid use of an incomplete type that is actually complete

我怕爱的太早我们不能终老 提交于 2019-12-10 01:23:37
问题 I'm not sure if it's a bug of the GCC compiler or the intended behavior of noexcept . Consider the following example: struct B { B(int) noexcept { } virtual void f() = 0; }; struct D: public B { using B::B; D() noexcept(noexcept(D{42})): B{42} { } void f() override { } }; int main() { B *b = new D{}; } If the noexcept is removed, it compiles. Anyway, as it is in the example, I got this error from GCC v5.3.1: test.cpp:8:31: error: invalid use of incomplete type ‘struct D’ D() noexcept(noexcept

noexcept, inheriting constructors and the invalid use of an incomplete type that is actually complete

老子叫甜甜 提交于 2019-12-05 00:29:33
I'm not sure if it's a bug of the GCC compiler or the intended behavior of noexcept . Consider the following example: struct B { B(int) noexcept { } virtual void f() = 0; }; struct D: public B { using B::B; D() noexcept(noexcept(D{42})): B{42} { } void f() override { } }; int main() { B *b = new D{}; } If the noexcept is removed, it compiles. Anyway, as it is in the example, I got this error from GCC v5.3.1: test.cpp:8:31: error: invalid use of incomplete type ‘struct D’ D() noexcept(noexcept(D{42})): B{42} { } ^ As far as I know, struct D is not an incomplete type, but inheriting constructors

Constructor inheritance failure with boost::multiprecision::mpz_int

南楼画角 提交于 2019-12-04 10:36:43
问题 I tried to create a class deriving from boost::multiprecision::mpz_int and to have it inherit the base class constructors: #include <boost/multiprecision/gmp.hpp> using namespace boost::multiprecision; struct Integer: mpz_int { using mpz_int::mpz_int; }; g++ 4.9.0 gives me the following error: main.cpp:8:20: error: 'template<class tag, class Arg1, class Arg2, class Arg3, class Arg4> Integer::Integer(const boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>&)' inherited from

Constructor inheritance failure with boost::multiprecision::mpz_int

风格不统一 提交于 2019-12-03 05:45:52
I tried to create a class deriving from boost::multiprecision::mpz_int and to have it inherit the base class constructors: #include <boost/multiprecision/gmp.hpp> using namespace boost::multiprecision; struct Integer: mpz_int { using mpz_int::mpz_int; }; g++ 4.9.0 gives me the following error : main.cpp:8:20: error: 'template<class tag, class Arg1, class Arg2, class Arg3, class Arg4> Integer::Integer(const boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>&)' inherited from 'boost::multiprecision::number<boost::multiprecision::backends::gmp_int>' using mpz_int::mpz_int; ^

C++11 inheriting constructors and access modifiers

橙三吉。 提交于 2019-11-27 04:28:38
Assuming the following layout: class Base { protected: Base(P1 p1, P2 p2, P3 p3); public: virtual void SomeMethod() = 0; } class Derived : public Base { public: using Base::Base; public: virtual void SomeMethod() override; }; Should I be able to specify Derived 's constructor as public here? VC++ gives the following error: cannot access protected member declared in class 'Derived' compiler has generated 'Derived::Derived' here [points to the using Base::Base line] see declaration of 'Derived' i.e. it's ignoring the access modifier above the inherited constructor. Is this a limitation of the