Created
March 24, 2022 15:29
-
-
Save nthery/1c0a7a2a6a7f187337429d69a211dc65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Templated constructor in derived class. | |
#include <utility> | |
struct B { | |
B(); | |
B(int); | |
B(const B&); | |
B(B&&); | |
int payload[24]; | |
}; | |
struct D : B { | |
D(); | |
D(double); | |
D(const D&); | |
D(D&&); | |
template<class ...Ts> | |
D(Ts&&... args) | |
: B(std::forward<Ts...>(args)...) {} | |
int more_payload[42]; | |
}; | |
void f() { | |
// Calls D::D() | |
D d0; | |
// Calls D::D(int) | |
D d1{42}; | |
// Calls D::D(const D&) not the templated constructor. | |
D d2{d1}; | |
// Calls D::D(double) | |
D d3{3.14}; | |
// Calls D::D<float>, not D::D(double) | |
D d4{3.14f}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment