Questions tagged [inheriting-constructors]
25 questions
43
votes
1 answer
C++11 inheriting constructors and access modifiers
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()…

Mark Ingram
- 71,849
- 51
- 176
- 230
18
votes
1 answer
In using-declaration, can dependent names render to constructors after template substitution?
In this example:
template
struct S : T
{
using T::X;
};
T::X is a dependent name that refers to the member X in T.
If S is instantiated with T = X:
struct X
{
X(int) {}
};
...
S s(42);
Will the using-declaration become…

Jamboree
- 5,139
- 2
- 16
- 36
15
votes
1 answer
Inheriting-Constructors + In-Class-Initialization of non-default constructabe type fails
I am encountering the following error in my project:
error: use of deleted function ‘C::C(int)’ note: ‘C::C(int)’ is
implicitly deleted because the default definition would be ill-formed:
error: use of deleted function ‘M::M()’
This is the code I…

BCS
- 75,627
- 68
- 187
- 294
13
votes
2 answers
C++ using declaration with typename in inheriting-constructors
While reading this question, I found a strange point:
template
class Subclass : public Baseclass
{
public:
using typename Baseclass::Baseclass;
// ^^^^^^^^
};
Since typename, Baseclass::Baseclass should be injected…

ikh
- 10,119
- 1
- 31
- 70
13
votes
1 answer
Constructor inheritance failure with boost::multiprecision::mpz_int
I tried to create a class deriving from boost::multiprecision::mpz_int and to have it inherit the base class constructors:
#include
using namespace boost::multiprecision;
struct Integer:
mpz_int
{
using…

Morwenn
- 21,684
- 12
- 93
- 152
12
votes
1 answer
noexcept, inheriting constructors and the invalid use of an incomplete type that is actually complete
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()…

skypjack
- 49,335
- 19
- 95
- 187
10
votes
2 answers
All versions of GCC struggle with default member initializer, that captures this, combined with inherited constructors
This story is similar to my previous question. All versions of GCC that support C++11, have this exact behaviour. I could not find any other compiler that struggles with my test case.
The test case:
struct BaseFooWrapper
{
BaseFooWrapper(int…

GreenScape
- 7,191
- 2
- 34
- 64
6
votes
1 answer
Access to own private constructors via derived class constructor inheritance
Consider:
struct B {
void f();
private:
B(int, int = 0);
};
struct D : B { using B::B; };
void B::f() {
auto a = D{0};
auto b = D(0);
auto c = D(0, 0);
D x{0};
D y(0);
D z(0, 0);
}
GCC accepts (since 7.1; previously…

ecatmur
- 152,476
- 27
- 293
- 366
6
votes
2 answers
Inheriting constructors and virtual base classes
I'm about to create an exception class hierarchy which conceptually looks somewhat like this:
#include
#include
class ExceptionBase : public std::runtime_error {
public:
ExceptionBase( const char * msg ) :…

Ralph Tandetzky
- 22,780
- 11
- 73
- 120
5
votes
1 answer
Are inheriting constructors noexcept(true) by default?
Here I found that:
Inheriting constructors [...] are all noexcept(true) by default, unless they are required to call a function that is noexcept(false), in which case these functions are noexcept(false).
Does it mean that in the following example…

skypjack
- 49,335
- 19
- 95
- 187
4
votes
1 answer
Inheriting constructor with a type alias in a template derived class
Please see the following code:
struct base {};
template
struct derived : T {
using base_type = T;
using base_type::T;
};
int main()
{
derived x;
}
GCC accepts this code, but Clang and MSVC reject it. Who is right and why?

Junekey Jeon
- 1,496
- 1
- 11
- 18
4
votes
2 answers
Inheriting constructors work only partially
I have following class, written so, as to work completely, whatever the typedef is:
class A
{
protected:
typedef uchar mDataType;
std::vector mData;
uint32 mWidth;
uint32 mHeight;
friend class C;
public:
A();
…

MKK
- 130
- 10
4
votes
3 answers
Inheriting constructors vs forwarding
C++11 allows inheriting constructors making it possible to avoid a lot of boilerplate, especially with something like a wrapper class. However, it seems like you could already achieve this functionality with variadic templates alone.
class…

Pradhan
- 16,391
- 3
- 44
- 59
4
votes
1 answer
Visual C++ 14 CTP3: c++11 inheriting constructor bug?
The following code snippet builds perfectly fine under Clang 3.4/3.5 (Xcode 5/6), but throws out the error under Visual C++ 14 CTP3:
1>------ Build started: Project: InheritingConstructor, Configuration:
Debug Win32 ------ 1> …

Dejavu
- 1,299
- 14
- 24
3
votes
0 answers
Inheriting constructors (GCC and clang disagree)
I'm trying to customize std::function and beginning with the following code:
#include
template
struct my_function;
template
struct my_function : std::function {
using…

Lingxi
- 14,579
- 2
- 37
- 93