Q:

Why am I allowed to initialize object of class Test by assigning integer constant in C++?

Here is my C++ code
#include<iostream>

class Test{
        int i;
public:
        Test() { }
        Test(int i){ 
                std::cout << "Constructor called" << std::endl;
                this->i = i;
        }
        void print(){
                std::cout << i << std::endl;
        }
};

int main(){
        Test t = 3;
        t.print();
        return 0;
}

I was amused when Test t = 3; worked. I do not understand why it is not giving compilation error.
I was under the impression that object of class Test should be created in one of the following ways. Are there other ways of creating object of class Test which are not covered in following list?
Test t1;
Test t2(2);
Test t3 = Test(3);
Test t4(t3);
Test t5 = Test(t4);
Test t6{2};
Test t7 = Test{3};
Test t8{t3};
Test t9 = Test{t4};
Test t10 = {10};

A:

This syntax:
Test t = 3;

is a form of copy-initialization. The effect of this is that the best user-defined-conversion-sequence is selected to initialize t. In this particular case, you have provided a conversion constructor Test(int) which is the best match and gets called.

