I was expecting an error to be thrown by compiler for initializing a c++ type from a temporary variable of another type.
template <bool>
struct A{
A(...);
};
template <> struct A<false>{
};
class B{
};
class C{
int i;
};
int main()
{
//A a;
B b;
C c(B());
A<false> aa(B());
cout << "Hello World!!" << endl;
}
Here I have specialized class A for nontype parameter of type bool and value false, so that it has compiler generated standard constructors only, which should not accept any other type as initializing parameter.
For simplification I have used class C with same result(no error in compilation).
But if I do C c(b); it results in error which I expect: error: no matching function for call to ‘C::C(B&)’