In this example, the last line fails to compile. I understand why, but I wonder how I can make the compiler understand that I want to call Class(const int &)
to create an unnamed instance, instead of trying to call the undefined default constructor and creating an instance named i
:
struct Class {
Class(const int &) {}
};
void foo() {
int i;
// Works
Class(int(i));
// Fails
Class(i);
}
1