Linked Questions

2 votes
2 answers
441 views

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); }...
mada's user avatar
  • 2,033
-1 votes
1 answer
107 views

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)...
semicolon_missing's user avatar
0 votes
1 answer
85 views

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 ...
Amir's user avatar
  • 309
0 votes
0 answers
91 views

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: ...
user3161924's user avatar
  • 2,547
0 votes
0 answers
64 views

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(...
Kaiyakha's user avatar
  • 2,075
348 votes
8 answers
420k views

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 ...
Sydius's user avatar
  • 14.5k
7 votes
1 answer
6k views

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 ...
Enlico's user avatar
  • 30.3k
3 votes
1 answer
237 views

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}} ...
Oliver Schönrock's user avatar
1 vote
1 answer
179 views

#include <iostream> struct U { template<typename T> operator T(); }; template<unsigned I> struct X : X<I - 1> {}; template<> struct X<0> {}; template<...
xmllmx's user avatar
  • 44.6k
1 vote
1 answer
107 views

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 ...
tmlen's user avatar
  • 9,230