Linked Questions
10 questions linked to/from Why does Clang 12 refuse to initialize aggregates in the C++20 way?
2 votes
2 answers
441 views
Automatic constructor inheritance in C++20 [duplicate]
I just have this code, and I wonder why this code compiles in C++20 and later, but it doesn't compile in C++17 and earlier. struct B { B(int){}; }; struct D : B { }; int main() { D d = D(10); }...
-1 votes
1 answer
107 views
why default constructor is not used in value initialisation in c++ [duplicate]
c++ primer says : The default constructor is used automatically whenever an object is default or value initialized. Default initialization happens • When we define nonstatic variables (§ 2.2.1, p. 43)...
0 votes
1 answer
85 views
Using struct constructor to create an struct instance in C++ [duplicate]
I am trying to wrap my mind around this talk: https://www.youtube.com/watch?v=FXfrojjIo80 I get an error on the following part. It is the simplified version. template<typename... Ts> struct ...
0 votes
0 answers
91 views
How do you call constructor of template base class of a non-template class member variable? [duplicate]
Given the below (omitted functions/data members) - how do I initialize the variable m_Class1Obj in Class3 using the templates constructor? template<class T> class ClassTemplate { protected: ...
0 votes
0 answers
64 views
Why is base constructor available via curly braces but not via parentheses? [duplicate]
I've come across the following issue. Here is a simple piece of code: struct Base { Base(int x) : x_{x} {} int get() { return x_; } private: int x_ = 0; }; struct Derived : Base {}; int main(...
348 votes
8 answers
420k views
Inheriting constructors
Why does this code: class A { public: explicit A(int x) {} }; class B: public A { }; int main(void) { B *b = new B(5); delete b; } Result in these errors: main.cpp: In function ...
7 votes
1 answer
6k views
Is it possible to emplace a std::array in a container? If it is how? If not, why? [duplicate]
Given the simple code #include <array> #include <vector> int main() { std::vector<std::array<int,3>> v; v.emplace_back(std::array<int,3>{1,2,3}); } I'm first of ...
3 votes
1 answer
237 views
why "missing double brace warning" for BaseClass Aggregate initialisation in Clang 12 but not Clang 13 or GCC 11?
This code compiles without warning in GCC 11 and Clang 13 (in C++20 mode) struct A { int x, y; }; struct B : A { }; int main () { A a{1,2}; B b{3,4}; // Clang 12 wants B b{{3,4}} ...
1 vote
1 answer
179 views
Why do gcc and clang give different results in aggregate initialization?
#include <iostream> struct U { template<typename T> operator T(); }; template<unsigned I> struct X : X<I - 1> {}; template<> struct X<0> {}; template<...
1 vote
1 answer
107 views
Using lambda function in constexpr constructor with std::tie
I'm trying to use a constexpr constructor in C++17 with a lambda that uses std::tie to initialize fields in a class from a tuple. The code is similar to this: #include <tuple> enum class Format ...