From a practical point of view: I would only use int a = 0;
.
The int a(0)
may be allowed but never used in practice in itself.
I think it should not bother you on your level, but let us go further.
Let's say that a
is a class, not an int.
class Demo{
public:
Demo(){};
Demo(int){};
};
Demo a;
Demo b(a);
Demo c = a; // clearly expressing copy-init
In this example both b(a)
and c=a
do the same, and I would discourage you using the fist solution. My reason is, that is looks similar to c(2)
which is a construction from arguments.
There are only two valid uses of this bracket-style initialization:
- initialization lists (
Demo(int i):data(i){}
if Demo has an int data member data
),
- new's:
Demo *p=new Demo(a); // copy constructing a pointer