Reading some code written by a coworker I stumbled on the use of constructor syntax to initialize a primitive type variable. Ie something like below:
#include <iostream>
int main()
{
using namespace std;
// initialized using assignement syntax (copy initialisation)
int titi = 20;
cout << "titi=" << titi << "\n"; // got 20 in titi, it works
// initialized using constructor syntax (direct initialization)
int toto(10);
cout << "toto=" << toto << "\n"; // got 10 in toto, it works
}
My natural tendency would be to stick with the assignement syntax, as it is the historical one and it's a no brainer, and there is obvious compatibility issues (consructor syntax won't qualify as valid C).
Still I wonder if there is any other non obvious difference between the two syntax ? If they are actually meaning the same thing ? And what are the pros and cons of one or the other form considering for instance future maintenance/code evolution issues or readability issues ?