The following code does not compile:
#include
#include
struct Foo
{
Foo() { std::cout << \"Foo()\" << std::
Another way to avoid the variadic constructor being selected is to supply all forms of the Bar
constructor.
It's a little more work, but avoids the complexity of enable_if, if that's important to you:
#include
#include
struct Foo
{
Foo() { std::cout << "Foo()" << std::endl; }
Foo(int) { std::cout << "Foo(int)" << std::endl; }
};
template
struct Bar
{
Foo foo;
Bar(const Bar&) { std::cout << "Bar(const Bar&)" << std::endl; }
Bar(Bar&) { std::cout << "Bar(Bar&)" << std::endl; }
Bar(Bar&&) { std::cout << "Bar(Bar&&)" << std::endl; }
template
Bar(Args&&... args) : foo(std::forward(args)...)
{
std::cout << "Bar(Args&&... args)" << std::endl;
}
};
int main()
{
Bar bar1{};
Bar bar2{bar1};
}