print<int,5> *p; //this is compiles. Why?
//in this line, *p gets no arguments(so it can not use the C'tor in the
//class), but there is no default C'tor. So how come it compiles?
This creates a pointer, not an object of any print<> type. Pointers don't have constructors, so it is uninitialized. You could initialize it with
1 2 3 4 5
int main()
{
print<int,5> p1(1);
print<int,5> *p = &p1;
}
in class print we wrote new C'tor, so the default C'tor was deleted.
//in this line, *p gets no arguments(so it can not use the C'tor in the
//class), but there is no default C'tor. So how come it compiles?
You didn't override the default constructor. You just made a different constructor.
In order to actually override the implicit default constructor that the compiler generates for you, you would have to write a constructor like this. print() : x(0) {}; // Should give x a default value
Basically no parameters. That is the default constructor (A constructor with no parameters, or all parameters have a default argument). So the reason why line 18 compiles is because you still have the implicitly generated default constructor.
EDIT: Ignore my half asleep madness ;p
print p3(3); //won't compile
You have no template parameters. The same goes with the rest of them.
You didn't override the default constructor. You just made a different constructor.
In order to actually override the implicit constructor that the compiler generates for you, you would have to write a constructor like this.
print() : x() {};
This is incorrect. The compiler only generates a default constructor if no other constructors of any kind are defined.
By defining the constructor print(int i), the OP prevents the compiler from automatically generating a default constructor, even though print(int i) is not a default constructor.